mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
4b04578e4c
commit
ecee29a03b
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
|
* src/NSString.m: Moved NXConstantString stuff out to NSGCString.m
|
||||||
NSString and add behaviours from NSGCString. Added ([-hash]),
|
* src/NSGCString.m: Added NXConstantString (inherits from NSGCString)
|
||||||
([-isEqual:]) and ([-isEqualToString:]) methods to avoid calling
|
and modified for efficient ([-isEqual:]) and ([-isEqualToString:])
|
||||||
NSGCStrings methods which use the _hash instance variable
|
methods.
|
||||||
(not present in strings produced by the @"..." compiler directive).
|
|
||||||
|
|
||||||
Thu Sep 30 17:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Thu Sep 30 17:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,18 @@
|
||||||
#include <gnustep/base/preface.h>
|
#include <gnustep/base/preface.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSData.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/IndexedCollection.h>
|
||||||
#include <gnustep/base/IndexedCollectionPrivate.h>
|
#include <gnustep/base/IndexedCollectionPrivate.h>
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
#include <gnustep/base/behavior.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 immutableClass;
|
||||||
static Class mutableClass;
|
static Class mutableClass;
|
||||||
|
static Class constantClass;
|
||||||
|
|
||||||
@implementation NSGCString
|
@implementation NSGCString
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ static Class mutableClass;
|
||||||
done = 1;
|
done = 1;
|
||||||
immutableClass = [NSGCString class];
|
immutableClass = [NSGCString class];
|
||||||
mutableClass = [NSGMutableCString class];
|
mutableClass = [NSGMutableCString class];
|
||||||
|
constantClass = [NXConstantString class];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +274,9 @@ static Class mutableClass;
|
||||||
Class c;
|
Class c;
|
||||||
if (anObject == self)
|
if (anObject == self)
|
||||||
return YES;
|
return YES;
|
||||||
c = ((NSGCString*)anObject)->isa; /* Hack. */
|
c = [anObject class];
|
||||||
if (c == immutableClass || c == mutableClass)
|
|
||||||
|
if (c == immutableClass || c == mutableClass || c == constantClass)
|
||||||
{
|
{
|
||||||
NSGCString *other = (NSGCString*)anObject;
|
NSGCString *other = (NSGCString*)anObject;
|
||||||
|
|
||||||
|
@ -299,8 +302,8 @@ static Class mutableClass;
|
||||||
{
|
{
|
||||||
Class c;
|
Class c;
|
||||||
|
|
||||||
c = ((NSGCString*)aString)->isa; /* Hack. */
|
c = [aString class];
|
||||||
if (c == immutableClass || c == mutableClass)
|
if (c == immutableClass || c == mutableClass || c == constantClass)
|
||||||
{
|
{
|
||||||
NSGCString *other = (NSGCString*)aString;
|
NSGCString *other = (NSGCString*)aString;
|
||||||
|
|
||||||
|
@ -557,3 +560,68 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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
|
@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…
Add table
Add a link
Reference in a new issue