mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Better NSString hash and comparison
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3028 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
577399616d
commit
7c6a778e4c
3 changed files with 80 additions and 102 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,10 +1,9 @@
|
|||
Sat Oct 3 08:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Sat Oct 3 23:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* src/NSString.m: Changed NXConstantString to inherit directly from
|
||||
NSString and add behaviours from NSGCString. Added ([-hash]),
|
||||
([-isEqual:]) and ([-isEqualToString:]) methods to avoid calling
|
||||
NSGCStrings methods which use the _hash instance variable
|
||||
(not present in strings produced by the @"..." compiler directive).
|
||||
* src/NSString.m: Moved NXConstantString stuff out to NSGCString.m
|
||||
* src/NSGCString.m: Added NXConstantString (inherits from NSGCString)
|
||||
and modified for efficient ([-isEqual:]) and ([-isEqualToString:])
|
||||
methods.
|
||||
|
||||
Thu Sep 30 17:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
|
|
|
@ -25,17 +25,18 @@
|
|||
#include <gnustep/base/preface.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <gnustep/base/NSString.h>
|
||||
#include <gnustep/base/NSGString.h>
|
||||
#include <gnustep/base/NSGCString.h>
|
||||
#include <gnustep/base/IndexedCollection.h>
|
||||
#include <gnustep/base/IndexedCollectionPrivate.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <gnustep/base/behavior.h>
|
||||
/* memcpy(), strlen(), strcmp() are gcc builtin's */
|
||||
|
||||
#include <gnustep/base//Unicode.h>
|
||||
#include <gnustep/base/Unicode.h>
|
||||
|
||||
static Class immutableClass;
|
||||
static Class mutableClass;
|
||||
static Class constantClass;
|
||||
|
||||
@implementation NSGCString
|
||||
|
||||
|
@ -47,6 +48,7 @@ static Class mutableClass;
|
|||
done = 1;
|
||||
immutableClass = [NSGCString class];
|
||||
mutableClass = [NSGMutableCString class];
|
||||
constantClass = [NXConstantString class];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,8 +274,9 @@ static Class mutableClass;
|
|||
Class c;
|
||||
if (anObject == self)
|
||||
return YES;
|
||||
c = ((NSGCString*)anObject)->isa; /* Hack. */
|
||||
if (c == immutableClass || c == mutableClass)
|
||||
c = [anObject class];
|
||||
|
||||
if (c == immutableClass || c == mutableClass || c == constantClass)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)anObject;
|
||||
|
||||
|
@ -299,8 +302,8 @@ static Class mutableClass;
|
|||
{
|
||||
Class c;
|
||||
|
||||
c = ((NSGCString*)aString)->isa; /* Hack. */
|
||||
if (c == immutableClass || c == mutableClass)
|
||||
c = [aString class];
|
||||
if (c == immutableClass || c == mutableClass || c == constantClass)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)aString;
|
||||
|
||||
|
@ -557,3 +560,68 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NXConstantString
|
||||
|
||||
/*
|
||||
* NXConstantString overrides [-dealloc] so that it is never deallocated.
|
||||
* If we pass an NXConstantString to another process it will never get
|
||||
* deallocated in the other process - causing a memory leak. So we tell
|
||||
* the DO system to use the super class instead.
|
||||
*/
|
||||
- (Class)classForPortCoder
|
||||
{
|
||||
return [self superclass];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
}
|
||||
|
||||
- (const char*) cString
|
||||
{
|
||||
return _contents_chars;
|
||||
}
|
||||
|
||||
- retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)z
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSZone*) zone
|
||||
{
|
||||
return NSDefaultMallocZone();
|
||||
}
|
||||
|
||||
- (NSStringEncoding) fastestEncoding
|
||||
{
|
||||
return NSASCIIStringEncoding;
|
||||
}
|
||||
|
||||
- (NSStringEncoding) smallestEncoding
|
||||
{
|
||||
return NSASCIIStringEncoding;
|
||||
}
|
||||
|
||||
- (unichar) characterAtIndex: (unsigned int)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
return (unichar)_contents_chars[index];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -2737,92 +2737,3 @@ else
|
|||
|
||||
@end
|
||||
|
||||
@implementation NXConstantString
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
BOOL beenHere = NO;
|
||||
|
||||
if (beenHere == NO) {
|
||||
beenHere = YES;
|
||||
class_add_behavior(self, [NSGCString class]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* NXConstantString overrides [-dealloc] so that it is never deallocated.
|
||||
* If we pass an NXConstantString to another process it will never get
|
||||
* deallocated in the other process - causing a memory leak. So we tell
|
||||
* the DO system to use the super class instead.
|
||||
*/
|
||||
- (Class)classForPortCoder
|
||||
{
|
||||
return [self superclass];
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
return [super hash];
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
return [super isEqual: anObject];
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToString: (NSString*)aString
|
||||
{
|
||||
return [super isEqualToString: aString];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
}
|
||||
|
||||
- (const char*) cString
|
||||
{
|
||||
return _contents_chars;
|
||||
}
|
||||
|
||||
- retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)z
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSZone*) zone
|
||||
{
|
||||
return NSDefaultMallocZone();
|
||||
}
|
||||
|
||||
- (NSStringEncoding) fastestEncoding
|
||||
{
|
||||
return NSASCIIStringEncoding;
|
||||
}
|
||||
|
||||
- (NSStringEncoding) smallestEncoding
|
||||
{
|
||||
return NSASCIIStringEncoding;
|
||||
}
|
||||
|
||||
- (unichar) characterAtIndex: (unsigned int)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
return (unichar)_contents_chars[index];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue