From b4c1a943775bae4bc7a69061e4af84d271b8faff Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 5 Mar 2010 05:44:39 +0000 Subject: [PATCH] use objc_getProtocol git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29841 72102866-910b-0410-8b05-ffd578937521 --- Source/Additions/GSObjCRuntime.m | 59 +------------------------------- Source/ObjectiveC2/runtime.c | 33 +++++++++++++++--- 2 files changed, 30 insertions(+), 62 deletions(-) diff --git a/Source/Additions/GSObjCRuntime.m b/Source/Additions/GSObjCRuntime.m index 11d048a04..0b8eee571 100644 --- a/Source/Additions/GSObjCRuntime.m +++ b/Source/Additions/GSObjCRuntime.m @@ -652,63 +652,6 @@ gs_string_hash(const char *s) return val; } -static inline Protocol * -gs_find_protocol_named_in_protocol_list(const char *name, - struct objc_protocol_list *pcllist) -{ - Protocol *p = NULL; - size_t i; - - while (pcllist != NULL) - { - for (i = 0; i < pcllist->count; i++) - { - p = (Protocol*)pcllist->list[i]; - if (strcmp([p name], name) == 0) - { - return p; - } - } - pcllist = pcllist->next; - } - return NULL; -} - -static inline Protocol * -gs_find_protocol_named(const char *name) -{ - Protocol *p = NULL; - Class cls; -#ifdef NeXT_RUNTIME - Class *clsList, *clsListStart; - unsigned int num; - - /* Setting the clearCache flag is a noop for the Apple runtime. */ - num = GSClassList(NULL, 0, NO); - clsList = malloc(sizeof(Class) * (num + 1)); - GSClassList(clsList, num, NO); - - clsListStart = clsList; - - while (p == NULL && (cls = *clsList++)) - { - p = gs_find_protocol_named_in_protocol_list(name, cls->protocols); - } - - free(clsListStart); - -#else - void *iterator = NULL; - - while (p == NULL && (cls = objc_next_class(&iterator))) - { - p = gs_find_protocol_named_in_protocol_list(name, cls->protocols); - } - -#endif - return p; -} - #define GSI_MAP_HAS_VALUE 1 #define GSI_MAP_RETAIN_KEY(M, X) #define GSI_MAP_RETAIN_VAL(M, X) @@ -794,7 +737,7 @@ GSProtocolFromName(const char *name) } else { - p = gs_find_protocol_named(name); + p = objc_getProtocol(name); if (p) { /* Use the protocol's name to save us from allocating diff --git a/Source/ObjectiveC2/runtime.c b/Source/ObjectiveC2/runtime.c index 519d23afa..759565029 100644 --- a/Source/ObjectiveC2/runtime.c +++ b/Source/ObjectiveC2/runtime.c @@ -994,6 +994,7 @@ objc_registerClassPair(Class cls) __objc_resolve_class_links(); } +/* static id objectNew(id cls) { @@ -1007,15 +1008,39 @@ objectNew(id cls) newIMP = (IMP) objc_msg_lookup((void *) cls, newSel); return newIMP((id) cls, newSel); } +*/ Protocol * objc_getProtocol(const char *name) { - // Protocols are not centrally registered in the GNU runtime. - Protocol *protocol = (Protocol *) (objectNew(objc_getClass("Protocol"))); + Protocol *p = NULL; + Class cls; + void *iterator = NULL; - protocol->protocol_name = (char *) name; - return protocol; + /* Protocols are not centrally registered in the GNU runtime. + * So we just find the first match we can. + */ + + while (p == NULL && (cls = objc_next_class(&iterator))) + { + struct objc_protocol_list *pcllist = cls->protocols; + size_t i; + + while (pcllist != NULL) + { + for (i = 0; i < pcllist->count; i++) + { + if (strcmp(pcllist->list[i]->protocol_name, name) == 0) + { + p = (Protocol*)pcllist->list[i]; + break; + } + } + pcllist = pcllist->next; + } + } + + return p; } BOOL