mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Implemented [hash] and [isEqual:] for NSHost and added some retain/release
macros to NSObject.h git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3197 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3e96691fc2
commit
5ac6523902
2 changed files with 59 additions and 0 deletions
|
@ -189,4 +189,36 @@ extern NSRecursiveLock *gnustep_global_lock;
|
|||
inModes: (NSArray*)modes;
|
||||
@end
|
||||
|
||||
/*
|
||||
* RETAIN(), RELEASE(), and AUTORELEASE() are placeholders for the
|
||||
* (possible) future day when we have garbage collecting.
|
||||
*/
|
||||
#define RETAIN(object) [object retain]
|
||||
#define RELEASE(object) [object release]
|
||||
#define AUTORELEASE(object) [object autorelease]
|
||||
|
||||
/*
|
||||
* ASSIGN(object,value) assignes the value to the object with
|
||||
* appropriate retain and release operations.
|
||||
*/
|
||||
#define ASSIGN(object,value) ({\
|
||||
if (value != object) \
|
||||
if (value) \
|
||||
{ \
|
||||
[value retain]; \
|
||||
if (object) \
|
||||
{ \
|
||||
[object release]; \
|
||||
} \
|
||||
object = value; \
|
||||
} \
|
||||
})
|
||||
|
||||
/*
|
||||
* DESTROY() is a release operation which also sets the object to be
|
||||
* a nil pointer for tidyness - we can't accidentally use a DESTROYED
|
||||
* object later.
|
||||
*/
|
||||
#define DESTROY(object) ([object release], object = nil)
|
||||
|
||||
#endif /* __NSObject_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -250,11 +250,38 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The OpenStep spec says that [-hash] must be the same for any two
|
||||
* objects that [-isEqual:] returns YES for. We have a problem in
|
||||
* that [-isEqualToHost:] is specified to return YES if any name or
|
||||
* address part of two hosts is the same. That means we can't
|
||||
* reasonably calculate a hash since two hosts with radically
|
||||
* different ivar contents may be 'equal'. The best I can think of
|
||||
* is for all hosts to hash to the same value - which makes it very
|
||||
* inefficient to store them in a set, dictionary, map or hash table.
|
||||
*/
|
||||
- (unsigned) hash
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)other
|
||||
{
|
||||
if (other == self)
|
||||
return YES;
|
||||
if ([other isKindOfClass: [NSHost class]])
|
||||
return [self isEqualToHost: (NSHost*)other];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToHost:(NSHost *)aHost
|
||||
{
|
||||
NSArray* a;
|
||||
int i;
|
||||
|
||||
if (aHost == self)
|
||||
return YES;
|
||||
|
||||
a = [aHost addresses];
|
||||
for (i = 0; i < [a count]; i++)
|
||||
if ([addresses containsObject:[a objectAtIndex:i]])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue