Made the selector name field into a union of the name (unregistered selectors) and the selector id / index (registered selectors), to more accurately reflect how it is used in the code.

This commit is contained in:
theraven 2011-03-15 17:27:26 +00:00
parent 5df6a42107
commit a2db6f58be
5 changed files with 21 additions and 19 deletions

View File

@ -28,7 +28,7 @@ static void collectMethodsForMethodListToSparseArray(
for (unsigned i=0 ; i<list->count ; i++)
{
//fprintf(stderr, "Adding method %s (%d)\n", sel_getName(list->methods[i].selector), PTR_TO_IDX(list->methods[i].selector->name));
SparseArrayInsert(sarray, PTR_TO_IDX(list->methods[i].selector->name),
SparseArrayInsert(sarray, list->methods[i].selector->index,
(void*)&list->methods[i]);
}
}
@ -197,7 +197,7 @@ static void update_dtable(dtable_t dtable)
uint32_t idx = 0;
while ((m = SparseArrayNext(methods, &idx)))
{
uint32_t idx = PTR_TO_IDX(m->selector->name);
uint32_t idx = m->selector->index;
struct slots_list *s = find_slot(idx, dtable->slots, old_slot_count);
if (NULL != s)
{
@ -297,7 +297,7 @@ static BOOL installMethodInDtable(Class class,
BOOL replaceExisting)
{
assert(__objc_uninstalled_dtable != dtable);
uint32_t sel_id = PTR_TO_IDX(method->selector->name);
uint32_t sel_id = method->selector->index;
struct objc_slot *slot = SparseArrayLookup(dtable, sel_id);
if (NULL != slot)
{
@ -578,7 +578,7 @@ void objc_send_initialize(id object)
initializeSel = sel_registerName("initialize");
}
struct objc_slot *initializeSlot =
objc_dtable_lookup(dtable, PTR_TO_IDX(initializeSel->name));
objc_dtable_lookup(dtable, initializeSel->index);
if (0 != initializeSlot)
{
@ -588,7 +588,7 @@ void objc_send_initialize(id object)
// is the superclass's metaclass' dtable.
dtable_t super_dtable = dtable_for_class(class->super_class->isa);
struct objc_slot *superSlot = objc_dtable_lookup(super_dtable,
PTR_TO_IDX(initializeSel->name));
initializeSel->index);
// Check that this IMP comes from the class, not from its
// superclass. We still have to use dtable_for_class() here
// because our +initialize call might be in response to a message

View File

@ -118,6 +118,4 @@ void * SparseArrayNext(SparseArray * sarray, uint32_t * index);
*/
SparseArray *SparseArrayCopy(SparseArray * sarray);
#define PTR_TO_IDX(x) ((uint32_t)(uintptr_t)x)
#endif //_SARRAY_H_INCLUDED_

View File

@ -22,7 +22,11 @@ struct sel_type_list
*/
struct objc_selector
{
const char * name;
union
{
const char *name;
uintptr_t index;
};
const char * types;
};

View File

@ -228,7 +228,7 @@ void __objc_init_selector_tables()
static SEL selector_lookup(const char *name, const char *types)
{
struct objc_selector sel = {name, types};
struct objc_selector sel = {{name}, types};
return selector_table_get(sel_table, &sel);
}
static inline void add_selector_to_table(SEL aSel, int32_t uid, uint32_t idx)
@ -396,14 +396,14 @@ BOOL sel_isEqual(SEL sel1, SEL sel2)
SEL sel_registerName(const char *selName)
{
if (NULL == selName) { return NULL; }
struct objc_selector sel = {selName, 0};
struct objc_selector sel = {{selName}, 0};
return objc_register_selector_copy(&sel);
}
SEL sel_registerTypedName_np(const char *selName, const char *types)
{
if (NULL == selName) { return NULL; }
struct objc_selector sel = {selName, types};
struct objc_selector sel = {{selName}, types};
return objc_register_selector_copy(&sel);
}
@ -483,7 +483,7 @@ void objc_register_selectors_from_list(struct objc_method_list *l)
for (int i=0 ; i<l->count ; i++)
{
Method m = &l->methods[i];
struct objc_selector sel = { (const char*)m->selector, m->types };
struct objc_selector sel = { {(const char*)m->selector}, m->types };
m->selector = objc_register_selector_copy(&sel);
}
}

View File

@ -51,7 +51,7 @@ Slot_t objc_msg_lookup_internal(id *receiver,
{
retry:;
Slot_t result = objc_dtable_lookup((*receiver)->isa->dtable,
PTR_TO_IDX(selector->name));
selector->index);
if (0 == result)
{
Class class = (*receiver)->isa;
@ -61,13 +61,13 @@ retry:;
{
objc_send_initialize(*receiver);
dtable = dtable_for_class(class);
result = objc_dtable_lookup(dtable, PTR_TO_IDX(selector->name));
result = objc_dtable_lookup(dtable, selector->index);
}
else
{
// Check again incase another thread updated the dtable while we
// weren't looking
result = objc_dtable_lookup(dtable, PTR_TO_IDX(selector->name));
result = objc_dtable_lookup(dtable, selector->index);
}
if (0 == result)
{
@ -147,7 +147,7 @@ Slot_t objc_slot_lookup_super(struct objc_super *super, SEL selector)
{
Class class = super->class;
Slot_t result = objc_dtable_lookup(dtable_for_class(class),
PTR_TO_IDX(selector->name));
selector->index);
if (0 == result)
{
// Dtable should always be installed in the superclass
@ -249,7 +249,7 @@ void objc_msg_profile(id receiver, IMP method,
*/
Slot_t objc_get_slot(Class cls, SEL selector)
{
Slot_t result = objc_dtable_lookup(cls->dtable, PTR_TO_IDX(selector->name));
Slot_t result = objc_dtable_lookup(cls->dtable, selector->index);
if (0 == result)
{
void *dtable = dtable_for_class(cls);
@ -258,13 +258,13 @@ Slot_t objc_get_slot(Class cls, SEL selector)
{
//objc_send_initialize((id)cls);
dtable = dtable_for_class(cls);
result = objc_dtable_lookup(dtable, PTR_TO_IDX(selector->name));
result = objc_dtable_lookup(dtable, selector->index);
}
else
{
// Check again incase another thread updated the dtable while we
// weren't looking
result = objc_dtable_lookup(dtable, PTR_TO_IDX(selector->name));
result = objc_dtable_lookup(dtable, selector->index);
}
if (NULL == result)
{