From c7ac1eafa2fade128bb89f6ebd817d74bd352c9f Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Mon, 12 Oct 2009 16:02:42 +0000 Subject: [PATCH] Turned Richards specific hash method into a generic one. --- -- M Source/NSColor.m M ChangeLog git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28812 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSColor.m | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8163f7b61..b72c822b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-10-12 Fred Kiefer + + * Source/NSColor.m (-hash): Turned Richards specific hash method + into a generic one. + 2009-10-12 Fred Kiefer * Source/NSColor.m: Remove special proxy handling introduced in diff --git a/Source/NSColor.m b/Source/NSColor.m index 2b728e5c3..589a48c33 100644 --- a/Source/NSColor.m +++ b/Source/NSColor.m @@ -1219,6 +1219,24 @@ systemColorWithName(NSString *name) return nil; } +- (NSUInteger) hash +{ + int nums = [self numberOfComponents]; + union { + uint8_t bytes[sizeof(float) * nums]; + float floats[nums]; + } u; + NSUInteger h = 0; + unsigned i; + + [self getComponents: u.floats]; + for (i = 0; i < sizeof(u); i++) + { + h = (h << 5) + h + u.bytes[i]; + } + return h; +} + - (int) numberOfComponents { [NSException raise: NSInternalInconsistencyException @@ -2037,24 +2055,6 @@ static NSRecursiveLock *namedColorLock = nil; *alpha = _alpha_component; } -- (NSUInteger) hash -{ - union { - uint8_t bytes[sizeof(float)*2]; - float floats[2]; - } u; - NSUInteger h = 0; - unsigned i; - - u.floats[0] = _white_component; - u.floats[1] = _alpha_component; - for (i = 0; i < sizeof(u); i++) - { - h = (h << 5) + h + u.bytes[i]; - } - return h; -} - - (BOOL) isEqual: (id)other { if (other == self)