Skip to content

Instantly share code, notes, and snippets.

@Programator2
Last active July 14, 2020 22:20
Show Gist options
  • Save Programator2/043ad39413b49701a8cf0f25cd04c04a to your computer and use it in GitHub Desktop.
Save Programator2/043ad39413b49701a8cf0f25cd04c04a to your computer and use it in GitHub Desktop.
Refactoring of class.c
/* vrati offset (u_int16_t), alebo -1 ak chyba */
/*
cinfo v constablovi uchovava pointer
cinfo_size uchovava pocet u_int32_t-bitovych slov od cinfo_offset
*/
int _class_alloc_cinfo(u_int16_t cinfo_size, uintptr_t *cinfo_mask, u_int16_t cinfo_offset)
{
int i;
for(i=0; i < cinfo_size && i < sizeof(cinfo_mask) * 8; i++) {
if (!(cinfo_mask & 1 << i)) {
*cinfo_mask |= 1 << i;
return cinfo_offset + i * sizeof(uintptr_t);
}
}
return -1;
}
int class_alloc_object_cinfo(struct class_s *c)
{
return _class_alloc_cinfo(c->cinfo_size, &c->cinfo_mask, c->cinfo_offset);
}
int class_alloc_subject_cinfo(struct class_s *c)
{
return _class_alloc_cinfo(c->subject.cinfo_size, &c->subject.cinfo_mask, c->subject.cinfo_offset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment