diff options
author | Nicola Pero <nicola@gcc.gnu.org> | 2004-06-04 01:12:20 +0000 |
---|---|---|
committer | Nicola Pero <nicola@gcc.gnu.org> | 2004-06-04 01:12:20 +0000 |
commit | 1600b7d6167562ce7dbf9cb9f18039e7db848a0e (patch) | |
tree | c9512905ada08a454e8be37435793f28454ed199 | |
parent | c759d454325f974380284ac54d342705e95e70d2 (diff) | |
download | gcc-1600b7d6167562ce7dbf9cb9f18039e7db848a0e.zip gcc-1600b7d6167562ce7dbf9cb9f18039e7db848a0e.tar.gz gcc-1600b7d6167562ce7dbf9cb9f18039e7db848a0e.tar.bz2 |
Improved [Protocol -isEqual:], now more correct and faster
From-SVN: r82619
-rw-r--r-- | libobjc/ChangeLog | 10 | ||||
-rw-r--r-- | libobjc/Protocol.m | 24 |
2 files changed, 33 insertions, 1 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index b64433a..d6ba1f2 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,3 +1,13 @@ +2004-06-03 Nicola Pero <n.pero@mi.flashnet.it> + + * Protocol.m ([-isEqual:]): Small optimizations returning + immediately if the argument is equal to self, and accessing + the argument's name directly if it's a protocol. + +2004-06-03 David Ayers <d.ayers@inode.at> + + * Protocol.m ([-isEqual:]): Test the class of the argument. + 2004-05-25 Andrew Pinski <pinskia@physics.uc.edu> * configure.ac (includedir): Rename to ... diff --git a/libobjc/Protocol.m b/libobjc/Protocol.m index a18d544..689d97e 100644 --- a/libobjc/Protocol.m +++ b/libobjc/Protocol.m @@ -150,11 +150,33 @@ struct objc_method_description_list { return hash; } +/* + * Equality between formal protocols is only formal (nothing to do + * with actually checking the list of methods they have!). Two formal + * Protocols are equal if and only if they have the same name. + * + * Please note (for comparisons with other implementations) that + * checking the names is equivalent to checking that Protocol A + * conforms to Protocol B and Protocol B conforms to Protocol A, + * because this happens iff they have the same name. If they have + * different names, A conforms to B if and only if A includes B, but + * the situation where A includes B and B includes A is a circular + * dependency between Protocols which is forbidden by the compiler, so + * A conforms to B and B conforms to A with A and B having different + * names is an impossible case. + */ - (BOOL) isEqual: (id)obj { - if (strcmp (protocol_name, [obj name]) == 0) + if (obj == self) return YES; + if ([obj isKindOf: [Protocol class]]) + { + if (strcmp (protocol_name, ((Protocol *)obj)->protocol_name) == 0) + return YES; + } + return NO; } @end + |