mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 02:01:03 +00:00
NSNumber rewrite
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6366 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1a8eaa3cec
commit
54e75a58b9
5 changed files with 1794 additions and 278 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,9 +1,18 @@
|
||||||
|
2000-03-23 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
NSNumber - more extensive rewrite/optimisation ...
|
||||||
|
* Headers/gnustep/base/NSValue.h: simplified
|
||||||
|
* Source/NSNumber.m: Implemented efficient abstract methods and
|
||||||
|
improved caching.
|
||||||
|
* Source/NSConcreteNumber.m: More efficient implementations including
|
||||||
|
some previously missing methods.
|
||||||
|
|
||||||
2000-03-23 Adam Fedor <fedor@gnu.org>
|
2000-03-23 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* configure.in: Check for vasprintf function
|
* configure.in: Check for vasprintf function
|
||||||
* config/config.vasprintf.c: New file.
|
* config/config.vasprintf.c: New file.
|
||||||
|
|
||||||
2000-03-19 Richard Frith-Macdonald <rfm@gnu.org>
|
2000-03-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
NSNumber optimisation ...
|
NSNumber optimisation ...
|
||||||
* Headers/gnustep/base/NSValue.h: Added a couple of GNUstep specific
|
* Headers/gnustep/base/NSValue.h: Added a couple of GNUstep specific
|
||||||
|
|
|
@ -114,7 +114,6 @@
|
||||||
|
|
||||||
- (NSComparisonResult) compare: (NSNumber*)otherNumber;
|
- (NSComparisonResult) compare: (NSNumber*)otherNumber;
|
||||||
- (BOOL) isEqualToNumber: (NSNumber*)otherNumber;
|
- (BOOL) isEqualToNumber: (NSNumber*)otherNumber;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#ifndef NO_GNUSTEP
|
#ifndef NO_GNUSTEP
|
||||||
|
@ -131,22 +130,8 @@
|
||||||
* Cache info for internal use by NSNumber concrete subclasses.
|
* Cache info for internal use by NSNumber concrete subclasses.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int typeOrder;
|
int typeLevel;
|
||||||
int typeNext;
|
void (*getValue)(NSNumber*, SEL, void*);
|
||||||
NSComparisonResult (*compValue)(NSNumber*, SEL, NSNumber*);
|
|
||||||
BOOL (*boolValue)(NSNumber*, SEL);
|
|
||||||
char (*charValue)(NSNumber*, SEL);
|
|
||||||
unsigned char (*unsignedCharValue)(NSNumber*, SEL);
|
|
||||||
short (*shortValue)(NSNumber*, SEL);
|
|
||||||
unsigned short (*unsignedShortValue)(NSNumber*, SEL);
|
|
||||||
int (*intValue)(NSNumber*, SEL);
|
|
||||||
unsigned int (*unsignedIntValue)(NSNumber*, SEL);
|
|
||||||
long (*longValue)(NSNumber*, SEL);
|
|
||||||
unsigned long (*unsignedLongValue)(NSNumber*, SEL);
|
|
||||||
long long (*longLongValue)(NSNumber*, SEL);
|
|
||||||
unsigned long long (*unsignedLongLongValue)(NSNumber*, SEL);
|
|
||||||
float (*floatValue)(NSNumber*, SEL);
|
|
||||||
double (*doubleValue)(NSNumber*, SEL);
|
|
||||||
} GSNumberInfo;
|
} GSNumberInfo;
|
||||||
|
|
||||||
GSNumberInfo *GSNumberInfoFromObject(NSNumber *o);
|
GSNumberInfo *GSNumberInfoFromObject(NSNumber *o);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
# line 1 "NSConcreteNumber.m" /* So gdb knows which file we are in */
|
# line 1 "NSConcreteNumber.m" /* So gdb knows which file we are in */
|
||||||
/* NSConcreteNumber - Object encapsulation of numbers
|
/* NSConcreteNumber - Object encapsulation of numbers
|
||||||
|
|
||||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
Copyright (C) 1993, 1994, 1996, 2000 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
|
||||||
|
Rewrite: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Date: Mar 2000
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
@ -36,113 +38,58 @@
|
||||||
defined to a number from 0 to 12 cooresponding to each number type */
|
defined to a number from 0 to 12 cooresponding to each number type */
|
||||||
#if TYPE_ORDER == 0
|
#if TYPE_ORDER == 0
|
||||||
# define NumberTemplate NSBoolNumber
|
# define NumberTemplate NSBoolNumber
|
||||||
# define TYPE_METHOD boolValue
|
|
||||||
# define TYPE_FORMAT @"%u"
|
# define TYPE_FORMAT @"%u"
|
||||||
# define NEXT_ORDER 1
|
# define TYPE_TYPE BOOL
|
||||||
# define NEXT_TYPE char
|
|
||||||
# define NEXT_METHOD charValue
|
|
||||||
#elif TYPE_ORDER == 1
|
#elif TYPE_ORDER == 1
|
||||||
# define NumberTemplate NSCharNumber
|
# define NumberTemplate NSCharNumber
|
||||||
# define TYPE_METHOD charValue
|
|
||||||
# define TYPE_FORMAT @"%c"
|
# define TYPE_FORMAT @"%c"
|
||||||
# define NEXT_ORDER 3
|
# define TYPE_TYPE char
|
||||||
# define NEXT_TYPE short
|
|
||||||
# define NEXT_METHOD shortValue
|
|
||||||
#elif TYPE_ORDER == 2
|
#elif TYPE_ORDER == 2
|
||||||
# define NumberTemplate NSUCharNumber
|
# define NumberTemplate NSUCharNumber
|
||||||
# define TYPE_METHOD unsignedCharValue
|
|
||||||
# define TYPE_FORMAT @"%c"
|
# define TYPE_FORMAT @"%c"
|
||||||
# define NEXT_ORDER 3
|
# define TYPE_TYPE unsigned char
|
||||||
# define NEXT_TYPE short
|
|
||||||
# define NEXT_METHOD shortValue
|
|
||||||
#elif TYPE_ORDER == 3
|
#elif TYPE_ORDER == 3
|
||||||
# define NumberTemplate NSShortNumber
|
# define NumberTemplate NSShortNumber
|
||||||
# define TYPE_METHOD shortValue
|
|
||||||
# define TYPE_FORMAT @"%hd"
|
# define TYPE_FORMAT @"%hd"
|
||||||
# define NEXT_ORDER 5
|
# define TYPE_TYPE short
|
||||||
# define NEXT_TYPE int
|
|
||||||
# define NEXT_METHOD intValue
|
|
||||||
#elif TYPE_ORDER == 4
|
#elif TYPE_ORDER == 4
|
||||||
# define NumberTemplate NSUShortNumber
|
# define NumberTemplate NSUShortNumber
|
||||||
# define TYPE_METHOD unsignedShortValue
|
|
||||||
# define TYPE_FORMAT @"%hu"
|
# define TYPE_FORMAT @"%hu"
|
||||||
# define NEXT_ORDER 5
|
# define TYPE_TYPE unsigned short
|
||||||
# define NEXT_TYPE int
|
|
||||||
# define NEXT_METHOD intValue
|
|
||||||
#elif TYPE_ORDER == 5
|
#elif TYPE_ORDER == 5
|
||||||
# define NumberTemplate NSIntNumber
|
# define NumberTemplate NSIntNumber
|
||||||
# define TYPE_METHOD intValue
|
|
||||||
# define TYPE_FORMAT @"%d"
|
# define TYPE_FORMAT @"%d"
|
||||||
# define NEXT_ORDER 7
|
# define TYPE_TYPE int
|
||||||
# define NEXT_TYPE long
|
|
||||||
# define NEXT_METHOD longValue
|
|
||||||
#elif TYPE_ORDER == 6
|
#elif TYPE_ORDER == 6
|
||||||
# define NumberTemplate NSUIntNumber
|
# define NumberTemplate NSUIntNumber
|
||||||
# define TYPE_METHOD unsignedIntValue
|
|
||||||
# define TYPE_FORMAT @"%u"
|
# define TYPE_FORMAT @"%u"
|
||||||
# define NEXT_ORDER 7
|
# define TYPE_TYPE unsigned int
|
||||||
# define NEXT_TYPE long
|
|
||||||
# define NEXT_METHOD longValue
|
|
||||||
#elif TYPE_ORDER == 7
|
#elif TYPE_ORDER == 7
|
||||||
# define NumberTemplate NSLongNumber
|
# define NumberTemplate NSLongNumber
|
||||||
# define TYPE_METHOD longValue
|
|
||||||
# define TYPE_FORMAT @"%ld"
|
# define TYPE_FORMAT @"%ld"
|
||||||
# define NEXT_ORDER 9
|
# define TYPE_TYPE long
|
||||||
# define NEXT_TYPE long long
|
|
||||||
# define NEXT_METHOD longLongValue
|
|
||||||
#elif TYPE_ORDER == 8
|
#elif TYPE_ORDER == 8
|
||||||
# define NumberTemplate NSULongNumber
|
# define NumberTemplate NSULongNumber
|
||||||
# define TYPE_METHOD unsignedLongValue
|
|
||||||
# define TYPE_FORMAT @"%lu"
|
# define TYPE_FORMAT @"%lu"
|
||||||
# define NEXT_ORDER 9
|
# define TYPE_TYPE unsigned long
|
||||||
# define NEXT_TYPE long long
|
|
||||||
# define NEXT_METHOD longLongValue
|
|
||||||
#elif TYPE_ORDER == 9
|
#elif TYPE_ORDER == 9
|
||||||
# define NumberTemplate NSLongLongNumber
|
# define NumberTemplate NSLongLongNumber
|
||||||
# define TYPE_METHOD longLongValue
|
|
||||||
# define TYPE_FORMAT @"%lld"
|
# define TYPE_FORMAT @"%lld"
|
||||||
# define NEXT_ORDER 11
|
# define TYPE_TYPE long long
|
||||||
# define NEXT_TYPE float
|
|
||||||
# define NEXT_METHOD floatValue
|
|
||||||
#elif TYPE_ORDER == 10
|
#elif TYPE_ORDER == 10
|
||||||
# define NumberTemplate NSULongLongNumber
|
# define NumberTemplate NSULongLongNumber
|
||||||
# define TYPE_METHOD unsignedLongLongValue
|
|
||||||
# define TYPE_FORMAT @"%llu"
|
# define TYPE_FORMAT @"%llu"
|
||||||
# define NEXT_ORDER 11
|
# define TYPE_TYPE unsigned long long
|
||||||
# define NEXT_TYPE float
|
|
||||||
# define NEXT_METHOD floatValue
|
|
||||||
#elif TYPE_ORDER == 11
|
#elif TYPE_ORDER == 11
|
||||||
# define NumberTemplate NSFloatNumber
|
# define NumberTemplate NSFloatNumber
|
||||||
# define TYPE_METHOD floatValue
|
|
||||||
# define TYPE_FORMAT @"%f"
|
# define TYPE_FORMAT @"%f"
|
||||||
# define NEXT_ORDER 12
|
# define TYPE_TYPE float
|
||||||
# define NEXT_TYPE double
|
|
||||||
# define NEXT_METHOD doubleValue
|
|
||||||
#elif TYPE_ORDER == 12
|
#elif TYPE_ORDER == 12
|
||||||
# define NumberTemplate NSDoubleNumber
|
# define NumberTemplate NSDoubleNumber
|
||||||
# define TYPE_METHOD doubleValue
|
|
||||||
# define TYPE_FORMAT @"%g"
|
# define TYPE_FORMAT @"%g"
|
||||||
# define NEXT_ORDER 12
|
# define TYPE_TYPE double
|
||||||
# define NEXT_TYPE double
|
|
||||||
# define NEXT_METHOD doubleValue
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@interface NSNumber (Private)
|
|
||||||
- (int) _typeNext;
|
|
||||||
- (int) _typeOrder;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NumberTemplate (Private)
|
|
||||||
- (int) _typeNext
|
|
||||||
{
|
|
||||||
return NEXT_ORDER;
|
|
||||||
}
|
|
||||||
- (int) _typeOrder
|
|
||||||
{
|
|
||||||
return TYPE_ORDER;
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NumberTemplate
|
@implementation NumberTemplate
|
||||||
|
|
||||||
- (id) initWithBytes: (const void*)value objCType: (const char*)type
|
- (id) initWithBytes: (const void*)value objCType: (const char*)type
|
||||||
|
@ -192,67 +139,67 @@
|
||||||
|
|
||||||
- (BOOL) boolValue
|
- (BOOL) boolValue
|
||||||
{
|
{
|
||||||
return data;
|
return (BOOL)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (char) charValue
|
- (char) charValue
|
||||||
{
|
{
|
||||||
return data;
|
return (char)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double) doubleValue
|
- (double) doubleValue
|
||||||
{
|
{
|
||||||
return data;
|
return (double)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) floatValue
|
- (float) floatValue
|
||||||
{
|
{
|
||||||
return data;
|
return (float)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) intValue
|
- (int) intValue
|
||||||
{
|
{
|
||||||
return data;
|
return (int)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long long) longLongValue
|
- (long long) longLongValue
|
||||||
{
|
{
|
||||||
return data;
|
return (long long)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long) longValue
|
- (long) longValue
|
||||||
{
|
{
|
||||||
return data;
|
return (long)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (short) shortValue
|
- (short) shortValue
|
||||||
{
|
{
|
||||||
return data;
|
return (short)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned char) unsignedCharValue
|
- (unsigned char) unsignedCharValue
|
||||||
{
|
{
|
||||||
return data;
|
return (unsigned char)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) unsignedIntValue
|
- (unsigned int) unsignedIntValue
|
||||||
{
|
{
|
||||||
return data;
|
return (unsigned int)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned long long) unsignedLongLongValue
|
- (unsigned long long) unsignedLongLongValue
|
||||||
{
|
{
|
||||||
return data;
|
return (unsigned long long)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned long) unsignedLongValue
|
- (unsigned long) unsignedLongValue
|
||||||
{
|
{
|
||||||
return data;
|
return (unsigned long)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned short) unsignedShortValue
|
- (unsigned short) unsignedShortValue
|
||||||
{
|
{
|
||||||
return data;
|
return (unsigned short)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSComparisonResult) compare: (NSNumber*)other
|
- (NSComparisonResult) compare: (NSNumber*)other
|
||||||
|
@ -265,68 +212,168 @@
|
||||||
}
|
}
|
||||||
info = GSNumberInfoFromObject(other);
|
info = GSNumberInfoFromObject(other);
|
||||||
|
|
||||||
/*
|
switch (info->typeLevel)
|
||||||
* If the two types are the same, or the other type can be promoted to ours.
|
|
||||||
*/
|
|
||||||
if (TYPE_ORDER == info->typeOrder || TYPE_ORDER >= info->typeNext)
|
|
||||||
{
|
{
|
||||||
typedef __typeof__(data) _dt;
|
case 0:
|
||||||
_dt other_data = (*(info->TYPE_METHOD))(other, @selector(TYPE_METHOD));
|
{
|
||||||
|
BOOL oData;
|
||||||
|
|
||||||
if (data == other_data)
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
{
|
if (data == oData)
|
||||||
return NSOrderedSame;
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
}
|
}
|
||||||
else if (data < other_data)
|
case 1:
|
||||||
{
|
{
|
||||||
return NSOrderedAscending;
|
char oData;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return NSOrderedDescending;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
* If we and the other object both promote to the same type
|
if (data == oData)
|
||||||
*/
|
return NSOrderedSame;
|
||||||
if (NEXT_ORDER == info->typeNext)
|
else if (data < oData)
|
||||||
{
|
return NSOrderedAscending;
|
||||||
int res;
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
unsigned char oData;
|
||||||
|
|
||||||
res = ((NEXT_TYPE)data)
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
- (*(info->NEXT_METHOD))(other, @selector(NEXT_METHOD));
|
if (data == oData)
|
||||||
if (res == 0)
|
return NSOrderedSame;
|
||||||
{
|
else if (data < oData)
|
||||||
return NSOrderedSame;
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
}
|
}
|
||||||
else if (res < 0)
|
case 3:
|
||||||
{
|
{
|
||||||
return NSOrderedAscending;
|
short oData;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return NSOrderedDescending;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSComparisonResult r;
|
|
||||||
|
|
||||||
/*
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
* We must be promoted to match the other.
|
if (data == oData)
|
||||||
*/
|
return NSOrderedSame;
|
||||||
r = (*(info->compValue))(other, @selector(compare:), self);
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
unsigned short oData;
|
||||||
|
|
||||||
if (r == NSOrderedAscending)
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
{
|
if (data == oData)
|
||||||
return NSOrderedDescending;
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
}
|
}
|
||||||
if (r == NSOrderedDescending)
|
case 5:
|
||||||
{
|
{
|
||||||
return NSOrderedAscending;
|
int oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
}
|
}
|
||||||
return r;
|
case 6:
|
||||||
|
{
|
||||||
|
unsigned int oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
long oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 8:
|
||||||
|
{
|
||||||
|
unsigned long oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 9:
|
||||||
|
{
|
||||||
|
long long oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 10:
|
||||||
|
{
|
||||||
|
unsigned long long oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 11:
|
||||||
|
{
|
||||||
|
float oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
case 12:
|
||||||
|
{
|
||||||
|
double oData;
|
||||||
|
|
||||||
|
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
|
||||||
|
if (data == oData)
|
||||||
|
return NSOrderedSame;
|
||||||
|
else if (data < oData)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"number type value for comparison"];
|
||||||
|
return NSOrderedSame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,22 +386,47 @@
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) copy
|
||||||
|
{
|
||||||
|
if (NSShouldRetainWithZone(self, NSDefaultMallocZone()))
|
||||||
|
return RETAIN(self);
|
||||||
|
else
|
||||||
|
return NSCopyObject(self, 0, NSDefaultMallocZone());
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) copyWithZone: (NSZone*)zone
|
||||||
|
{
|
||||||
|
if (NSShouldRetainWithZone(self, zone))
|
||||||
|
return RETAIN(self);
|
||||||
|
else
|
||||||
|
return NSCopyObject(self, 0, zone);
|
||||||
|
}
|
||||||
|
|
||||||
// Override these from NSValue
|
// Override these from NSValue
|
||||||
- (void) getValue: (void*)value
|
- (void) getValue: (void*)value
|
||||||
{
|
{
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Cannot copy value into NULL pointer"];
|
format: @"Cannot copy value into NULL pointer"];
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
}
|
}
|
||||||
memcpy(value, &data, objc_sizeof_type([self objCType]));
|
memcpy(value, &data, objc_sizeof_type(@encode(TYPE_TYPE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (const char*) objCType
|
- (const char*) objCType
|
||||||
{
|
{
|
||||||
typedef __typeof__(data) _dt;
|
return @encode(TYPE_TYPE);
|
||||||
return @encode(_dt);
|
}
|
||||||
|
|
||||||
|
- (id) nonretainedObjectValue
|
||||||
|
{
|
||||||
|
return (id)(void*)&data;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void*) pointerValue
|
||||||
|
{
|
||||||
|
return (void*)&data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSCoding
|
// NSCoding
|
||||||
|
@ -370,16 +442,14 @@
|
||||||
return [super replacementObjectForPortCoder: aCoder];
|
return [super replacementObjectForPortCoder: aCoder];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeWithCoder: coder
|
- (void) encodeWithCoder: (NSCoder*)coder
|
||||||
{
|
{
|
||||||
const char *type = [self objCType];
|
[coder encodeValueOfObjCType: @encode(TYPE_TYPE) at: &data];
|
||||||
[coder encodeValueOfObjCType: type at: &data];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: coder
|
- (id) initWithCoder: (NSCoder*)coder
|
||||||
{
|
{
|
||||||
const char *type = [self objCType];
|
[coder decodeValueOfObjCType: @encode(TYPE_TYPE) at: &data];
|
||||||
[coder decodeValueOfObjCType: type at: &data];
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1594
Source/NSNumber.m
1594
Source/NSNumber.m
File diff suppressed because it is too large
Load diff
|
@ -1777,27 +1777,45 @@ handle_printf_atsign (FILE *stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a new string with the path component given in aString
|
/* Returns a new string with the path component given in aString
|
||||||
appended to the receiver. Raises an exception if aString starts with
|
* appended to the receiver.
|
||||||
a '/'. Checks the receiver to see if the last letter is a '/', if it
|
* Removes trailing separators and multiple separators.
|
||||||
is not, a '/' is appended before appending aString */
|
*/
|
||||||
- (NSString*) stringByAppendingPathComponent: (NSString*)aString
|
- (NSString*) stringByAppendingPathComponent: (NSString*)aString
|
||||||
{
|
{
|
||||||
unsigned length;
|
unsigned length = [self length];
|
||||||
|
unsigned aLength = [aString length];
|
||||||
|
unichar buf[length+aLength+1];
|
||||||
|
|
||||||
if ([aString length] == 0)
|
[self getCharacters: buf];
|
||||||
return AUTORELEASE([self copy]);
|
if (aLength > 0)
|
||||||
length = [self length];
|
{
|
||||||
if (length == 0)
|
buf[length++] = pathSepChar;
|
||||||
return AUTORELEASE([aString copy]);
|
[aString getCharacters: &buf[length]];
|
||||||
|
}
|
||||||
|
length += aLength;
|
||||||
|
while (length > 1 && pathSepMember(buf[length-1]) == YES)
|
||||||
|
{
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
aLength = length - 1;
|
||||||
|
while (aLength > 1)
|
||||||
|
{
|
||||||
|
if (pathSepMember(buf[aLength]) == YES)
|
||||||
|
{
|
||||||
|
if (pathSepMember(buf[aLength-1]) == YES)
|
||||||
|
{
|
||||||
|
unsigned pos;
|
||||||
|
|
||||||
if (pathSepMember([aString characterAtIndex: 0]) == YES)
|
for (pos = aLength+1; pos < length; pos++)
|
||||||
[NSException raise: NSGenericException
|
{
|
||||||
format: @"attempt to append illegal path component"];
|
buf[pos-1] = buf[pos];
|
||||||
|
}
|
||||||
if (pathSepMember([self characterAtIndex: length-1]) == YES)
|
length--;
|
||||||
return [self stringByAppendingString: aString];
|
}
|
||||||
else
|
}
|
||||||
return [self stringByAppendingFormat: @"%@%@", pathSepString, aString];
|
aLength--;
|
||||||
|
}
|
||||||
|
return [NSString stringWithCharacters: buf length: length];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a new string with the path extension given in aString
|
/* Returns a new string with the path extension given in aString
|
||||||
|
@ -2192,30 +2210,34 @@ handle_printf_atsign (FILE *stream,
|
||||||
|
|
||||||
- (NSArray*) pathComponents
|
- (NSArray*) pathComponents
|
||||||
{
|
{
|
||||||
NSMutableArray *a;
|
NSMutableArray *a;
|
||||||
NSArray *r;
|
NSArray *r;
|
||||||
|
|
||||||
a = [[self componentsSeparatedByString: pathSepString] mutableCopy];
|
a = [[self componentsSeparatedByString: pathSepString] mutableCopy];
|
||||||
if ([a count] > 0) {
|
if ([a count] > 0)
|
||||||
int i;
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
/* If the path began with a '/' then the first path component must
|
/* If the path began with a '/' then the first path component must
|
||||||
* be a '/' rather than an empty string so that our output could be
|
* be a '/' rather than an empty string so that our output could be
|
||||||
* fed into [+pathWithComponents: ]
|
* fed into [+pathWithComponents: ]
|
||||||
*/
|
*/
|
||||||
if ([[a objectAtIndex: 0] length] == 0) {
|
if ([[a objectAtIndex: 0] length] == 0)
|
||||||
[a replaceObjectAtIndex: 0 withObject: pathSepString];
|
{
|
||||||
|
[a replaceObjectAtIndex: 0 withObject: pathSepString];
|
||||||
}
|
}
|
||||||
/* Any empty path components (except a trailing one) must be removed. */
|
/* Any empty path components (except a trailing one) must be removed. */
|
||||||
for (i = [a count] - 2; i > 0; i--) {
|
for (i = [a count] - 2; i > 0; i--)
|
||||||
if ([[a objectAtIndex: i] length] == 0) {
|
{
|
||||||
[a removeObjectAtIndex: i];
|
if ([[a objectAtIndex: i] length] == 0)
|
||||||
|
{
|
||||||
|
[a removeObjectAtIndex: i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r = [a copy];
|
r = [a copy];
|
||||||
RELEASE(a);
|
RELEASE(a);
|
||||||
return AUTORELEASE(r);
|
return AUTORELEASE(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) stringsByAppendingPaths: (NSArray*)paths
|
- (NSArray*) stringsByAppendingPaths: (NSArray*)paths
|
||||||
|
|
Loading…
Reference in a new issue