[ObjC] Make GPBFileDescriptor better meet NSObject requirements.

Since it really just wraps some basic types, there are lots of instances
that are actually the same content wise, so to better match the contract
for NSObject it should compare the fields.

PiperOrigin-RevId: 505167021
pull/11680/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 9904c12b03
commit f17a629d6d
  1. 22
      objectivec/GPBDescriptor.m

@ -325,7 +325,7 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
return result;
}
- (id)copyWithZone:(__unused NSZone *)zone {
- (instancetype)copyWithZone:(__unused NSZone *)zone {
return [self retain];
}
@ -395,6 +395,26 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
[super dealloc];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
}
if (![other isKindOfClass:[GPBFileDescriptor class]]) {
return NO;
}
GPBFileDescriptor *otherFile = other;
// objcPrefix can be nil, otherwise, straight up compare.
return (syntax_ == otherFile->syntax_ && [package_ isEqual:otherFile->package_] &&
(objcPrefix_ == otherFile->objcPrefix_ ||
(otherFile->objcPrefix_ && [objcPrefix_ isEqual:otherFile->objcPrefix_])));
}
- (NSUInteger)hash {
// The prefix is recommended to be the same for a given package, so just hash
// the package.
return [package_ hash];
}
@end
@implementation GPBOneofDescriptor

Loading…
Cancel
Save