diff --git a/ChangeLog b/ChangeLog index 51c91d3..f08e5fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jul 30 17:45:21 2003 Nicola Pero + + * Protocol.m ([-conformsTo:]): If the argument is nil, return NO. + ([-hash], [-isEqual:]): New methods. + (Suggestion by Jeremy Bettis ) + 2001-07-04 Richard Frith-Macdonald * Protocol.m: ([-descriptionForClassMethod:]) diff --git a/Protocol.m b/Protocol.m index 56f3370..d98861e 100644 --- a/Protocol.m +++ b/Protocol.m @@ -56,6 +56,9 @@ struct objc_method_description_list { size_t i; struct objc_protocol_list* proto_list; + if (aProtocolObject == nil) + return NO; + if (!strcmp(aProtocolObject->protocol_name, self->protocol_name)) return YES; @@ -133,4 +136,29 @@ struct objc_method_description_list { 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