summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2017-11-12 00:27:09 +0100
committerJonathan Schleifer <js@heap.zone>2017-11-12 00:27:09 +0100
commit3635046707befbd6b2353512e627076442eceb18 (patch)
tree5ab17dbb27ccae3870ef48fade5b8dc575719059
parente3c7aa953d8000b2e79bf81df2058e74f9784b63 (diff)
Small optimization for -[isEqual:]
-rw-r--r--src/OFArray.m3
-rw-r--r--src/OFArray_adjacent.m3
-rw-r--r--src/OFArray_adjacentSubarray.m3
-rw-r--r--src/OFData.m3
-rw-r--r--src/OFDate.m3
-rw-r--r--src/OFDictionary.m3
-rw-r--r--src/OFDictionary_hashtable.m17
-rw-r--r--src/OFHTTPCookie.m30
-rw-r--r--src/OFHTTPRequest.m3
-rw-r--r--src/OFIntrospection.m6
-rw-r--r--src/OFList.m3
-rw-r--r--src/OFMapTable.m3
-rw-r--r--src/OFMessagePackExtension.m3
-rw-r--r--src/OFNumber.m3
-rw-r--r--src/OFObject.m2
-rw-r--r--src/OFPair.m3
-rw-r--r--src/OFSandbox.m69
-rw-r--r--src/OFSet.m11
-rw-r--r--src/OFSet_hashtable.m3
-rw-r--r--src/OFTriple.m3
-rw-r--r--src/OFURL.m3
-rw-r--r--src/OFXMLAttribute.m3
-rw-r--r--src/OFXMLCDATA.m3
-rw-r--r--src/OFXMLCharacters.m3
-rw-r--r--src/OFXMLComment.m3
-rw-r--r--src/OFXMLElement.m3
-rw-r--r--src/OFXMLProcessingInstructions.m3
27 files changed, 139 insertions, 59 deletions
diff --git a/src/OFArray.m b/src/OFArray.m
index e9fd8e80..f039f542 100644
--- a/src/OFArray.m
+++ b/src/OFArray.m
@@ -511,6 +511,9 @@ static struct {
OFArray *otherArray;
size_t count;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFArray class]])
return false;
diff --git a/src/OFArray_adjacent.m b/src/OFArray_adjacent.m
index 6246dadb..265f64ec 100644
--- a/src/OFArray_adjacent.m
+++ b/src/OFArray_adjacent.m
@@ -283,6 +283,9 @@
id const *objects, *otherObjects;
size_t count;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFArray_adjacent class]] &&
![object isKindOfClass: [OFMutableArray_adjacent class]])
return [super isEqual: object];
diff --git a/src/OFArray_adjacentSubarray.m b/src/OFArray_adjacentSubarray.m
index 9233e847..c25eb2ba 100644
--- a/src/OFArray_adjacentSubarray.m
+++ b/src/OFArray_adjacentSubarray.m
@@ -31,6 +31,9 @@
OFArray *otherArray;
id const *objects, *otherObjects;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFArray_adjacent class]] &&
![object isKindOfClass: [OFMutableArray_adjacent class]])
return [super isEqual: object];
diff --git a/src/OFData.m b/src/OFData.m
index 2184f026..78f6afb1 100644
--- a/src/OFData.m
+++ b/src/OFData.m
@@ -419,6 +419,9 @@ _references_to_categories_of_OFData(void)
{
OFData *data;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFData class]])
return false;
diff --git a/src/OFDate.m b/src/OFDate.m
index 9c48b687..a248a918 100644
--- a/src/OFDate.m
+++ b/src/OFDate.m
@@ -358,6 +358,9 @@ tmAndTzToTime(struct tm *tm, int16_t *tz)
{
OFDate *otherDate;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFDate class]])
return false;
diff --git a/src/OFDictionary.m b/src/OFDictionary.m
index 77b0faf7..bf48e457 100644
--- a/src/OFDictionary.m
+++ b/src/OFDictionary.m
@@ -409,6 +409,9 @@ static OFCharacterSet *URLQueryPartAllowedCharacterSet = nil;
OFEnumerator *keyEnumerator, *objectEnumerator;
id key;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFDictionary class]])
return false;
diff --git a/src/OFDictionary_hashtable.m b/src/OFDictionary_hashtable.m
index 850240dc..1abcb809 100644
--- a/src/OFDictionary_hashtable.m
+++ b/src/OFDictionary_hashtable.m
@@ -310,17 +310,20 @@ static const of_map_table_functions_t objectFunctions = {
return [_mapTable count];
}
-- (bool)isEqual: (id)dictionary
+- (bool)isEqual: (id)object
{
- OFDictionary_hashtable *dictionary_;
+ OFDictionary_hashtable *dictionary;
- if (![dictionary isKindOfClass: [OFDictionary_hashtable class]] &&
- ![dictionary isKindOfClass: [OFMutableDictionary_hashtable class]])
- return [super isEqual: dictionary];
+ if (object == self)
+ return true;
- dictionary_ = (OFDictionary_hashtable *)dictionary;
+ if (![object isKindOfClass: [OFDictionary_hashtable class]] &&
+ ![object isKindOfClass: [OFMutableDictionary_hashtable class]])
+ return [super isEqual: object];
- return [dictionary_->_mapTable isEqual: _mapTable];
+ dictionary = (OFDictionary_hashtable *)object;
+
+ return [dictionary->_mapTable isEqual: _mapTable];
}
- (bool)containsObject: (id)object
diff --git a/src/OFHTTPCookie.m b/src/OFHTTPCookie.m
index 3cb37360..f9cae111 100644
--- a/src/OFHTTPCookie.m
+++ b/src/OFHTTPCookie.m
@@ -328,31 +328,35 @@ handleAttribute(OFHTTPCookie *cookie, OFString *name, OFString *value)
[super dealloc];
}
-- (bool)isEqual: (id)otherObject
+- (bool)isEqual: (id)object
{
- OFHTTPCookie *other;
+ OFHTTPCookie *cookie;
- if (![otherObject isKindOfClass: [OFHTTPCookie class]])
+ if (object == self)
+ return true;
+
+ if (![object isKindOfClass: [OFHTTPCookie class]])
return false;
- other = otherObject;
+ cookie = object;
- if (![_name isEqual: other->_name])
+ if (![cookie->_name isEqual: _name])
return false;
- if (![_value isEqual: other->_value])
+ if (![cookie->_value isEqual: _value])
return false;
- if (_domain != other->_domain && ![_domain isEqual: other->_domain])
+ if (cookie->_domain != _domain && ![cookie->_domain isEqual: _domain])
return false;
- if (_path != other->_path && ![_path isEqual: other->_path])
+ if (cookie->_path != _path && ![cookie->_path isEqual: _path])
return false;
- if (_expires != other->_expires && ![_expires isEqual: other->_expires])
+ if (cookie->_expires != _expires &&
+ ![cookie->_expires isEqual: _expires])
return false;
- if (_secure != other->_secure)
+ if (cookie->_secure != _secure)
return false;
- if (_HTTPOnly != other->_HTTPOnly)
+ if (cookie->_HTTPOnly != _HTTPOnly)
return false;
- if (_extensions != other->_extensions &&
- ![_extensions isEqual: other->_extensions])
+ if (cookie->_extensions != _extensions &&
+ ![cookie->_extensions isEqual: _extensions])
return false;
return true;
diff --git a/src/OFHTTPRequest.m b/src/OFHTTPRequest.m
index 859d3eac..f244f2e2 100644
--- a/src/OFHTTPRequest.m
+++ b/src/OFHTTPRequest.m
@@ -149,6 +149,9 @@ of_http_request_method_from_string(const char *string)
{
OFHTTPRequest *request;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFHTTPRequest class]])
return false;
diff --git a/src/OFIntrospection.m b/src/OFIntrospection.m
index 3aa8a557..4218d6c9 100644
--- a/src/OFIntrospection.m
+++ b/src/OFIntrospection.m
@@ -87,6 +87,9 @@
{
OFMethod *method;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFMethod class]])
return false;
@@ -322,6 +325,9 @@
{
OFProperty *otherProperty;
+ if (object == self)
+ return true;
+
if ([object isKindOfClass: [OFProperty class]])
return false;
diff --git a/src/OFList.m b/src/OFList.m
index 6e668a66..5104e748 100644
--- a/src/OFList.m
+++ b/src/OFList.m
@@ -206,6 +206,9 @@
OFList *list;
of_list_object_t *iter, *iter2;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFList class]])
return false;
diff --git a/src/OFMapTable.m b/src/OFMapTable.m
index 55837ddb..f9fbfafe 100644
--- a/src/OFMapTable.m
+++ b/src/OFMapTable.m
@@ -197,6 +197,9 @@ defaultEqual(void *object1, void *object2)
{
OFMapTable *mapTable;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFMapTable class]])
return false;
diff --git a/src/OFMessagePackExtension.m b/src/OFMessagePackExtension.m
index ac7d9397..95d92422 100644
--- a/src/OFMessagePackExtension.m
+++ b/src/OFMessagePackExtension.m
@@ -162,6 +162,9 @@
{
OFMessagePackExtension *extension;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFMessagePackExtension class]])
return false;
diff --git a/src/OFNumber.m b/src/OFNumber.m
index ab0094fc..3544fdac 100644
--- a/src/OFNumber.m
+++ b/src/OFNumber.m
@@ -735,6 +735,9 @@
{
OFNumber *number;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFNumber class]])
return false;
diff --git a/src/OFObject.m b/src/OFObject.m
index 5b5083a5..00db5086 100644
--- a/src/OFObject.m
+++ b/src/OFObject.m
@@ -994,7 +994,7 @@ _references_to_categories_of_OFObject(void)
- (bool)isEqual: (id)object
{
- return (self == object);
+ return (object == self);
}
- (uint32_t)hash
diff --git a/src/OFPair.m b/src/OFPair.m
index e539f993..41385501 100644
--- a/src/OFPair.m
+++ b/src/OFPair.m
@@ -65,6 +65,9 @@
{
OFPair *pair;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFPair class]])
return false;
diff --git a/src/OFSandbox.m b/src/OFSandbox.m
index bbd7000f..d33ef0af 100644
--- a/src/OFSandbox.m
+++ b/src/OFSandbox.m
@@ -342,76 +342,77 @@
return copy;
}
-- (bool)isEqual: (id)otherObject
+- (bool)isEqual: (id)object
{
- OFSandbox *otherSandbox;
+ OFSandbox *sandbox;
- if (![otherObject isKindOfClass: [OFSandbox class]])
+ if (object == self)
+ return true;
+
+ if (![object isKindOfClass: [OFSandbox class]])
return false;
- otherSandbox = otherObject;
+ sandbox = object;
- if (otherSandbox->_allowsStdIO != _allowsStdIO)
+ if (sandbox->_allowsStdIO != _allowsStdIO)
return false;
- if (otherSandbox->_allowsReadingFiles != _allowsReadingFiles)
+ if (sandbox->_allowsReadingFiles != _allowsReadingFiles)
return false;
- if (otherSandbox->_allowsWritingFiles != _allowsWritingFiles)
+ if (sandbox->_allowsWritingFiles != _allowsWritingFiles)
return false;
- if (otherSandbox->_allowsCreatingFiles != _allowsCreatingFiles)
+ if (sandbox->_allowsCreatingFiles != _allowsCreatingFiles)
return false;
- if (otherSandbox->_allowsCreatingSpecialFiles !=
- _allowsCreatingSpecialFiles)
+ if (sandbox->_allowsCreatingSpecialFiles != _allowsCreatingSpecialFiles)
return false;
- if (otherSandbox->_allowsTemporaryFiles != _allowsTemporaryFiles)
+ if (sandbox->_allowsTemporaryFiles != _allowsTemporaryFiles)
return false;
- if (otherSandbox->_allowsIPSockets != _allowsIPSockets)
+ if (sandbox->_allowsIPSockets != _allowsIPSockets)
return false;
- if (otherSandbox->_allowsMulticastSockets != _allowsMulticastSockets)
+ if (sandbox->_allowsMulticastSockets != _allowsMulticastSockets)
return false;
- if (otherSandbox->_allowsChangingFileAttributes !=
+ if (sandbox->_allowsChangingFileAttributes !=
_allowsChangingFileAttributes)
return false;
- if (otherSandbox->_allowsFileOwnerChanges != _allowsFileOwnerChanges)
+ if (sandbox->_allowsFileOwnerChanges != _allowsFileOwnerChanges)
return false;
- if (otherSandbox->_allowsFileLocks != _allowsFileLocks)
+ if (sandbox->_allowsFileLocks != _allowsFileLocks)
return false;
- if (otherSandbox->_allowsUNIXSockets != _allowsUNIXSockets)
+ if (sandbox->_allowsUNIXSockets != _allowsUNIXSockets)
return false;
- if (otherSandbox->_allowsDNS != _allowsDNS)
+ if (sandbox->_allowsDNS != _allowsDNS)
return false;
- if (otherSandbox->_allowsUserDatabaseReading !=
- _allowsUserDatabaseReading)
+ if (sandbox->_allowsUserDatabaseReading != _allowsUserDatabaseReading)
return false;
- if (otherSandbox->_allowsFileDescriptorSending !=
+ if (sandbox->_allowsFileDescriptorSending !=
_allowsFileDescriptorSending)
return false;
- if (otherSandbox->_allowsFileDescriptorReceiving !=
+ if (sandbox->_allowsFileDescriptorReceiving !=
_allowsFileDescriptorReceiving)
return false;
- if (otherSandbox->_allowsTape != _allowsTape)
+ if (sandbox->_allowsTape != _allowsTape)
return false;
- if (otherSandbox->_allowsTTY != _allowsTTY)
+ if (sandbox->_allowsTTY != _allowsTTY)
return false;
- if (otherSandbox->_allowsProcessOperations != _allowsProcessOperations)
+ if (sandbox->_allowsProcessOperations != _allowsProcessOperations)
return false;
- if (otherSandbox->_allowsExec != _allowsExec)
+ if (sandbox->_allowsExec != _allowsExec)
return false;
- if (otherSandbox->_allowsProtExec != _allowsProtExec)
+ if (sandbox->_allowsProtExec != _allowsProtExec)
return false;
- if (otherSandbox->_allowsSetTime != _allowsSetTime)
+ if (sandbox->_allowsSetTime != _allowsSetTime)
return false;
- if (otherSandbox->_allowsPS != _allowsPS)
+ if (sandbox->_allowsPS != _allowsPS)
return false;
- if (otherSandbox->_allowsVMInfo != _allowsVMInfo)
+ if (sandbox->_allowsVMInfo != _allowsVMInfo)
return false;
- if (otherSandbox->_allowsChangingProcessRights !=
+ if (sandbox->_allowsChangingProcessRights !=
_allowsChangingProcessRights)
return false;
- if (otherSandbox->_allowsPF != _allowsPF)
+ if (sandbox->_allowsPF != _allowsPF)
return false;
- if (otherSandbox->_allowsAudio != _allowsAudio)
+ if (sandbox->_allowsAudio != _allowsAudio)
return false;
- if (otherSandbox->_allowsBPF != _allowsBPF)
+ if (sandbox->_allowsBPF != _allowsBPF)
return false;
return true;
diff --git a/src/OFSet.m b/src/OFSet.m
index b26c4676..06472103 100644
--- a/src/OFSet.m
+++ b/src/OFSet.m
@@ -278,17 +278,20 @@ static struct {
- (bool)isEqual: (id)object
{
- OFSet *otherSet;
+ OFSet *set;
+
+ if (object == self)
+ return true;
if (![object isKindOfClass: [OFSet class]])
return false;
- otherSet = object;
+ set = object;
- if ([otherSet count] != [self count])
+ if ([set count] != [self count])
return false;
- return [otherSet isSubsetOfSet: self];
+ return [set isSubsetOfSet: self];
}
- (uint32_t)hash
diff --git a/src/OFSet_hashtable.m b/src/OFSet_hashtable.m
index 23f84cba..cb006469 100644
--- a/src/OFSet_hashtable.m
+++ b/src/OFSet_hashtable.m
@@ -244,6 +244,9 @@ static const of_map_table_functions_t objectFunctions = { NULL };
{
OFSet_hashtable *set;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFSet_hashtable class]] &&
![object isKindOfClass: [OFMutableSet_hashtable class]] &&
![object isKindOfClass: [OFCountedSet_hashtable class]])
diff --git a/src/OFTriple.m b/src/OFTriple.m
index 05bd339f..a3cc24a3 100644
--- a/src/OFTriple.m
+++ b/src/OFTriple.m
@@ -75,6 +75,9 @@
{
OFTriple *triple;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFTriple class]])
return false;
diff --git a/src/OFURL.m b/src/OFURL.m
index c6f67a9b..7c7e5407 100644
--- a/src/OFURL.m
+++ b/src/OFURL.m
@@ -592,6 +592,9 @@ static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil;
{
OFURL *URL;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFURL class]])
return false;
diff --git a/src/OFXMLAttribute.m b/src/OFXMLAttribute.m
index 39fa5aaf..9226acd8 100644
--- a/src/OFXMLAttribute.m
+++ b/src/OFXMLAttribute.m
@@ -121,6 +121,9 @@
{
OFXMLAttribute *attribute;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLAttribute class]])
return false;
diff --git a/src/OFXMLCDATA.m b/src/OFXMLCDATA.m
index 168fc016..d36a931f 100644
--- a/src/OFXMLCDATA.m
+++ b/src/OFXMLCDATA.m
@@ -76,6 +76,9 @@
{
OFXMLCDATA *CDATA;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLCDATA class]])
return false;
diff --git a/src/OFXMLCharacters.m b/src/OFXMLCharacters.m
index f01183a0..706a59e7 100644
--- a/src/OFXMLCharacters.m
+++ b/src/OFXMLCharacters.m
@@ -76,6 +76,9 @@
{
OFXMLCharacters *characters;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLCharacters class]])
return false;
diff --git a/src/OFXMLComment.m b/src/OFXMLComment.m
index 5e61a106..514b172b 100644
--- a/src/OFXMLComment.m
+++ b/src/OFXMLComment.m
@@ -78,6 +78,9 @@
{
OFXMLComment *comment;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLComment class]])
return false;
diff --git a/src/OFXMLElement.m b/src/OFXMLElement.m
index 2aac6ef5..37b62fbc 100644
--- a/src/OFXMLElement.m
+++ b/src/OFXMLElement.m
@@ -1033,6 +1033,9 @@ static Class CDATAClass = Nil;
{
OFXMLElement *element;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLElement class]])
return false;
diff --git a/src/OFXMLProcessingInstructions.m b/src/OFXMLProcessingInstructions.m
index a7fce6e7..bc03c950 100644
--- a/src/OFXMLProcessingInstructions.m
+++ b/src/OFXMLProcessingInstructions.m
@@ -78,6 +78,9 @@
{
OFXMLProcessingInstructions *processingInstructions;
+ if (object == self)
+ return true;
+
if (![object isKindOfClass: [OFXMLProcessingInstructions class]])
return false;