summaryrefslogtreecommitdiff
path: root/libobjc/Protocol.m
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-04 01:12:20 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-04 01:12:20 +0000
commitff2b971f2eafe8b3cc8bf54eacf0f0b80e3cfa2b (patch)
treec9512905ada08a454e8be37435793f28454ed199 /libobjc/Protocol.m
parent9659da90301d4e69d7518c9d302bbb09b8c8063c (diff)
downloadgcc-ff2b971f2eafe8b3cc8bf54eacf0f0b80e3cfa2b.tar.gz
Improved [Protocol -isEqual:], now more correct and faster
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82619 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libobjc/Protocol.m')
-rw-r--r--libobjc/Protocol.m24
1 files changed, 23 insertions, 1 deletions
diff --git a/libobjc/Protocol.m b/libobjc/Protocol.m
index a18d544db40..689d97e73de 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
+