Optimisation updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4401 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-12 14:37:58 +00:00
parent f001c36343
commit 2e5303ee74
4 changed files with 153 additions and 147 deletions

View file

@ -1,7 +1,9 @@
Sat Jun 12 10:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Sat Jun 12 15:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSConcreteValue.m: Implemented [hash and isEqualToValue * Source/NSConcreteValue.m: Implemented [hash and isEqualToValue
* Source/NSCTemplateValue.m: Implemented hash * Source/include/NSConcreteValue.h: Change NSString ivar to char* for
performance reasons.
* Source/NSCTemplateValue.m: Implemented hash and optimised.
Thu Jun 4 13:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Thu Jun 4 13:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -1,6 +1,6 @@
/* NSConcreteValue - Interface for Concrete NSValue classes /* NSConcreteValue - Interface for Concrete NSValue classes
Copyright (C) 1993,1994 Free Software Foundation, Inc. Copyright (C) 1993,1994,1995,1999 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu> Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: Mar 1995 Date: Mar 1995
@ -30,7 +30,7 @@
@interface NSConcreteValue : NSValue @interface NSConcreteValue : NSValue
{ {
void *data; void *data;
NSString *objctype; char *objctype;
} }
@end @end

View file

@ -28,6 +28,7 @@
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <base/preface.h> #include <base/preface.h>
#include <base/fast.x>
/* This file should be run through a preprocessor with the macro TYPE_ORDER /* This file should be run through a preprocessor with the macro TYPE_ORDER
defined to a number from 0 to 4 cooresponding to each value type */ defined to a number from 0 to 4 cooresponding to each value type */
@ -57,7 +58,7 @@
// Allocating and Initializing // Allocating and Initializing
- initValue:(const void *)value - (id) initValue: (const void *)value
withObjCType: (const char *)type withObjCType: (const char *)type
{ {
typedef _dt = data; typedef _dt = data;
@ -69,7 +70,8 @@
// Accessing Data // Accessing Data
- (void) getValue: (void *)value - (void) getValue: (void *)value
{ {
if (!value) { if (!value)
{
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"Cannot copy value into NULL buffer"]; format: @"Cannot copy value into NULL buffer"];
/* NOT REACHED */ /* NOT REACHED */
@ -79,7 +81,8 @@
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if ([other isKindOfClass: [self class]]) { if (other != nil && fastInstanceIsKindOfClass(other, fastClass(self)))
{
return [self isEqualToValue: other]; return [self isEqualToValue: other];
} }
return NO; return NO;
@ -88,7 +91,9 @@
- (BOOL) isEqualToValue: (NSValue*)aValue - (BOOL) isEqualToValue: (NSValue*)aValue
{ {
typedef _dt = data; typedef _dt = data;
if ([aValue isKindOfClass: [self class]]) {
if (aValue != nil && fastInstanceIsKindOfClass(aValue, fastClass(self)))
{
_dt val = [aValue TYPE_METHOD]; _dt val = [aValue TYPE_METHOD];
#if TYPE_ORDER == 0 #if TYPE_ORDER == 0
return [data isEqual: val]; return [data isEqual: val];
@ -103,10 +108,9 @@
else else
return NO; return NO;
#elif TYPE_ORDER == 3 #elif TYPE_ORDER == 3
if (data.origin.x == val.origin.x && if (data.origin.x == val.origin.x && data.origin.y == val.origin.y
data.origin.y == val.origin.y && && data.size.width == val.size.width
data.size.width == val.size.width && && data.size.height == val.size.height)
data.size.height == val.size.height)
return YES; return YES;
else else
return NO; return NO;
@ -133,9 +137,8 @@
int i; int i;
val.d = data.x + data.y; val.d = data.x + data.y;
for (i = 0; i < sizeof(double); i++) { for (i = 0; i < sizeof(double); i++)
hash += val.c[i]; hash += val.c[i];
}
return hash; return hash;
#elif TYPE_ORDER == 2 #elif TYPE_ORDER == 2
return (unsigned)(gsaddr)data; return (unsigned)(gsaddr)data;
@ -148,9 +151,8 @@
int i; int i;
val.d = data.origin.x + data.origin.y + data.size.width + data.size.height; val.d = data.origin.x + data.origin.y + data.size.width + data.size.height;
for (i = 0; i < sizeof(double); i++) { for (i = 0; i < sizeof(double); i++)
hash += val.c[i]; hash += val.c[i];
}
return hash; return hash;
#elif TYPE_ORDER == 4 #elif TYPE_ORDER == 4
union { union {
@ -161,9 +163,8 @@
int i; int i;
val.d = data.width + data.height; val.d = data.width + data.height;
for (i = 0; i < sizeof(double); i++) { for (i = 0; i < sizeof(double); i++)
hash += val.c[i]; hash += val.c[i];
}
return hash; return hash;
#endif #endif
} }

View file

@ -1,5 +1,5 @@
/* NSConcreteValue - Object encapsulation for C types. /* NSConcreteValue - Object encapsulation for C types.
Copyright (C) 1993,1994 Free Software Foundation, Inc. Copyright (C) 1993,1994,1995,1999 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu> Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: Mar 1995 Date: Mar 1995
@ -29,6 +29,7 @@
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSZone.h> #include <Foundation/NSZone.h>
#include <base/preface.h> #include <base/preface.h>
#include <base/fast.x>
/* This is the real, general purpose value object. I've implemented all the /* This is the real, general purpose value object. I've implemented all the
methods here (like pointValue) even though most likely, other concrete methods here (like pointValue) even though most likely, other concrete
@ -44,24 +45,29 @@
@implementation NSConcreteValue @implementation NSConcreteValue
// NSCopying // NSCopying
- deepen - (id) deepen
{ {
void *old_ptr; void *old_ptr;
char *old_typ;
int size; int size;
size = objc_sizeof_type([objctype cString]); size = objc_sizeof_type(objctype);
old_ptr = data; old_ptr = data;
data = (void *)NSZoneMalloc([self zone], size); data = (void *)NSZoneMalloc(fastZone(self), size);
NS_CHECK_MALLOC(data) NS_CHECK_MALLOC(data)
memcpy(data, old_ptr, size); memcpy(data, old_ptr, size);
objctype = [objctype copyWithZone:[self zone]]; old_typ = objctype;
objctype = (char *)NSZoneMalloc(fastZone(self), strlen(old_typ)+1);
NS_CHECK_MALLOC(objctype)
strcpy(objctype, old_typ);
return self; return self;
} }
// Allocating and Initializing // Allocating and Initializing
- initValue:(const void *)value - (id) initValue: (const void *)value
withObjCType: (const char *)type withObjCType: (const char *)type
{ {
int size; int size;
@ -85,38 +91,40 @@
return nil; return nil;
} }
data = (void *)NSZoneMalloc([self zone], size); data = (void *)NSZoneMalloc(fastZone(self), size);
NS_CHECK_MALLOC(data) NS_CHECK_MALLOC(data)
memcpy(data, value, size); memcpy(data, value, size);
objctype = [[NSString stringWithCString:type] retain]; objctype = (char *)NSZoneMalloc(fastZone(self), strlen(type)+1);
NS_CHECK_MALLOC(objctype)
strcpy(objctype, type);
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
if (objctype) if (objctype)
[objctype release]; NSZoneFree(fastZone(self), objctype);
if (data) if (data)
NSZoneFree([self zone], data); NSZoneFree(fastZone(self), data);
[super dealloc]; [super dealloc];
} }
// Accessing Data // Accessing Data
- (void) getValue: (void *)value - (void) getValue: (void *)value
{ {
if (!value) { if (!value)
{
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"Cannot copy value into NULL buffer"]; format: @"Cannot copy value into NULL buffer"];
/* NOT REACHED */ /* NOT REACHED */
} }
memcpy( value, data, objc_sizeof_type([objctype cString]) ); memcpy(value, data, objc_sizeof_type(objctype));
} }
- (unsigned) hash - (unsigned) hash
{ {
const char* type = [objctype cString]; unsigned size = objc_sizeof_type(objctype);
unsigned size = objc_sizeof_type(type);
unsigned hash = 0; unsigned hash = 0;
while (size-- > 0) while (size-- > 0)
@ -128,18 +136,15 @@
{ {
const char* type; const char* type;
if ([aValue class] != [self class]) if (fastClass(aValue) != fastClass(self))
return NO; return NO;
type = [objctype cString]; if (strcmp(objctype, ((NSConcreteValue*)aValue)->objctype) != 0)
if (strcmp(type, [aValue objCType]) != 0)
return NO; return NO;
else else
{ {
unsigned size = objc_sizeof_type(type); unsigned size = objc_sizeof_type(objctype);
char buf[size];
[aValue getValue: buf]; if (memcmp(((NSConcreteValue*)aValue)->data, data, size) != 0)
if (memcmp(buf, data, size) != 0)
return NO; return NO;
return YES; return YES;
} }
@ -147,7 +152,7 @@
- (const char *)objCType - (const char *)objCType
{ {
return [objctype cString]; return objctype;
} }
// FIXME: need to check to make sure these hold the right values... // FIXME: need to check to make sure these hold the right values...
@ -181,7 +186,7 @@
int size; int size;
NSData *rep; NSData *rep;
size = objc_sizeof_type([objctype cString]); size = objc_sizeof_type(objctype);
rep = [NSData dataWithBytes: data length: size]; rep = [NSData dataWithBytes: data length: size];
return [NSString stringWithFormat: @"(%@) %@", objctype, [rep description]]; return [NSString stringWithFormat: @"(%@) %@", objctype, [rep description]];
} }
@ -189,13 +194,11 @@
// NSCoding // NSCoding
- (void) encodeWithCoder: (NSCoder *)coder - (void) encodeWithCoder: (NSCoder *)coder
{ {
const char *type;
[super encodeWithCoder: coder]; [super encodeWithCoder: coder];
// FIXME: Do we need to check for encoding void, void * or will // FIXME: Do we need to check for encoding void, void * or will
// NSCoder do this for us? // NSCoder do this for us?
type = [objctype cString]; [coder encodeValueOfObjCType: @encode(char *) at: &objctype];
[coder encodeValueOfObjCType:@encode(char *) at:&type]; [coder encodeValueOfObjCType: objctype at: &data];
[coder encodeValueOfObjCType:type at:&data];
} }
- (id) initWithCoder: (NSCoder *)coder - (id) initWithCoder: (NSCoder *)coder