Polish isEqual of options

pull/16190/head
Muxi Yan 6 years ago
parent d40e828d53
commit ae623ea5b6
  1. 43
      src/objective-c/GRPCClient/GRPCCallOptions.m
  2. 2
      src/objective-c/GRPCClient/private/GRPCChannelPool.m

@ -44,6 +44,17 @@ static const id kDefaultLogContext = nil;
static NSString *const kDefaultChannelPoolDomain = nil;
static const NSUInteger kDefaultChannelID = 0;
// Check if two objects are equal. Returns YES if both are nil;
BOOL areObjectsEqual(id obj1, id obj2) {
if (obj1 == obj2) {
return YES;
}
if (obj1 == nil || obj2 == nil) {
return NO;
}
return [obj1 isEqual:obj2];
}
@implementation GRPCCallOptions {
@protected
NSString *_serverAuthority;
@ -232,9 +243,8 @@ static const NSUInteger kDefaultChannelID = 0;
}
- (BOOL)hasChannelOptionsEqualTo:(GRPCCallOptions *)callOptions {
if (!(callOptions.userAgentPrefix == _userAgentPrefix ||
[callOptions.userAgentPrefix isEqualToString:_userAgentPrefix]))
return NO;
if (callOptions == nil) return NO;
if (!areObjectsEqual(callOptions.userAgentPrefix, _userAgentPrefix)) return NO;
if (!(callOptions.responseSizeLimit == _responseSizeLimit)) return NO;
if (!(callOptions.compressionAlgorithm == _compressionAlgorithm)) return NO;
if (!(callOptions.retryEnabled == _retryEnabled)) return NO;
@ -243,27 +253,14 @@ static const NSUInteger kDefaultChannelID = 0;
if (!(callOptions.connectMinTimeout == _connectMinTimeout)) return NO;
if (!(callOptions.connectInitialBackoff == _connectInitialBackoff)) return NO;
if (!(callOptions.connectMaxBackoff == _connectMaxBackoff)) return NO;
if (!(callOptions.additionalChannelArgs == _additionalChannelArgs ||
[callOptions.additionalChannelArgs isEqualToDictionary:_additionalChannelArgs]))
return NO;
if (!(callOptions.PEMRootCertificates == _PEMRootCertificates ||
[callOptions.PEMRootCertificates isEqualToString:_PEMRootCertificates]))
return NO;
if (!(callOptions.PEMPrivateKey == _PEMPrivateKey ||
[callOptions.PEMPrivateKey isEqualToString:_PEMPrivateKey]))
return NO;
if (!(callOptions.PEMCertChain == _PEMCertChain ||
[callOptions.PEMCertChain isEqualToString:_PEMCertChain]))
return NO;
if (!(callOptions.hostNameOverride == _hostNameOverride ||
[callOptions.hostNameOverride isEqualToString:_hostNameOverride]))
return NO;
if (!areObjectsEqual(callOptions.additionalChannelArgs, _additionalChannelArgs)) return NO;
if (!areObjectsEqual(callOptions.PEMRootCertificates, _PEMRootCertificates)) return NO;
if (!areObjectsEqual(callOptions.PEMPrivateKey, _PEMPrivateKey)) return NO;
if (!areObjectsEqual(callOptions.PEMCertChain, _PEMCertChain)) return NO;
if (!areObjectsEqual(callOptions.hostNameOverride, _hostNameOverride)) return NO;
if (!(callOptions.transportType == _transportType)) return NO;
if (!(callOptions.logContext == _logContext || [callOptions.logContext isEqual:_logContext]))
return NO;
if (!(callOptions.channelPoolDomain == _channelPoolDomain ||
[callOptions.channelPoolDomain isEqualToString:_channelPoolDomain]))
return NO;
if (!areObjectsEqual(callOptions.logContext, _logContext)) return NO;
if (!areObjectsEqual(callOptions.channelPoolDomain, _channelPoolDomain)) return NO;
if (!(callOptions.channelID == _channelID)) return NO;
return YES;

@ -151,7 +151,7 @@ extern const char *kCFStreamVarName;
return NO;
}
GRPCChannelConfiguration *obj = (GRPCChannelConfiguration *)object;
if (!(obj.host == _host || [obj.host isEqualToString:_host])) return NO;
if (!(obj.host == _host || (_host != nil && [obj.host isEqualToString:_host]))) return NO;
if (!(obj.callOptions == _callOptions || [obj.callOptions hasChannelOptionsEqualTo:_callOptions]))
return NO;

Loading…
Cancel
Save