Missing Protocol methods.
Nicola Pero
nicola@brainstorm.co.uk
Wed Jul 30 18:12:00 GMT 2003
A small patch adding a few missing methods to Protocol.
Protocol inherits from Object but does not implement -hash and isEqual:.
Ok to apply ?
-------------- next part --------------
Index: Protocol.m
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/Protocol.m,v
retrieving revision 1.4
diff -u -r1.4 Protocol.m
--- Protocol.m 23 May 2003 20:04:58 -0000 1.4
+++ Protocol.m 30 Jul 2003 18:10:20 -0000
@@ -56,6 +56,9 @@
size_t i;
struct objc_protocol_list* proto_list;
+ if (aProtocolObject == nil)
+ return NO;
+
if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
return YES;
@@ -126,5 +129,30 @@
return NULL;
}
+
+- (unsigned) hash
+{
+
+ /* Compute a hash of the protocol_name; use the same hash algorithm
+ * that we use for class names; protocol names and class names are
+ * somewhat similar types of string spaces.
+ */
+ int hash = 0, index;
+
+ for (index = 0; protocol_name[index] != '\0'; index++)
+ {
+ hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index];
+ }
+ hash = (hash ^ (hash >> 10) ^ (hash >> 20));
+
+ return hash;
+}
+- (BOOL) isEqual: (id)obj
+{
+ if (strcmp (protocol_name, [obj name]) == 0)
+ return YES;
+
+ return NO;
+}
@end
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/ChangeLog,v
retrieving revision 1.97
diff -u -r1.97 ChangeLog
--- ChangeLog 10 Jul 2003 09:24:51 -0000 1.97
+++ ChangeLog 30 Jul 2003 18:10:20 -0000
@@ -1,3 +1,9 @@
+Wed Jul 30 17:45:21 2003 Nicola Pero <n.pero@mi.flashnet.it>
+
+ * Protocol.m ([-conformsTo:]): If the argument is nil, return NO.
+ ([-hash], [-isEqual:]): New methods.
+ (Suggestion by Jeremy Bettis <jeremy@deadbeef.com>)
+
Thu Jul 10 10:27:43 2003 Nicola Pero <n.pero@mi.flashnet.it>
libobjc/9969
More information about the Gcc-patches
mailing list