mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Polish last few changes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11619 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6ab80e775b
commit
3cc1227360
3 changed files with 136 additions and 63 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2001-12-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSValue.m: polish last set of changes -
|
||||||
|
Optimisation ... cut memory allocation/deallocation to a minimum.
|
||||||
|
Versioning ... set NSValue version number and attempt to decode
|
||||||
|
old format objects.
|
||||||
|
Simplification ... remove redundant code in placeholder class.
|
||||||
|
Fixes ... allocate new objects in correct memory zone, I think a few
|
||||||
|
others I forgot.
|
||||||
|
* Source/NSNumberFormatter.m (-initWithCoder:): Avoid unnecessary
|
||||||
|
autorelease/retain sequences. (-init): Fix illegal re-initialisation
|
||||||
|
of initialised values and avoid unnecessary use of autorelease.
|
||||||
|
|
||||||
2001-12-03 Laurent Julliard <laurent@moldus.org>
|
2001-12-03 Laurent Julliard <laurent@moldus.org>
|
||||||
|
|
||||||
* Source/NSNumberFormatter.m (-initWithCoder:): decoded objects
|
* Source/NSNumberFormatter.m (-initWithCoder:): decoded objects
|
||||||
|
|
|
@ -155,13 +155,17 @@
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
|
id o;
|
||||||
|
|
||||||
_allowsFloats = YES;
|
_allowsFloats = YES;
|
||||||
_decimalSeparator = '.';
|
_decimalSeparator = '.';
|
||||||
_thousandSeparator = ',';
|
_thousandSeparator = ',';
|
||||||
[self setAttributedStringForNil: AUTORELEASE([[NSAttributedString new]
|
o = [[NSAttributedString alloc] initWithString: @""];
|
||||||
initWithString: @""])];
|
[self setAttributedStringForNil: o];
|
||||||
[self setAttributedStringForNotANumber: AUTORELEASE([[NSAttributedString new]
|
RELEASE(o);
|
||||||
initWithString: @"NaN"])];
|
o = [[NSAttributedString alloc] initWithString: @"NaN"];
|
||||||
|
[self setAttributedStringForNotANumber: o];
|
||||||
|
RELEASE(o);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -174,16 +178,19 @@
|
||||||
[decoder decodeValueOfObjCType: @encode(unichar) at: &_thousandSeparator];
|
[decoder decodeValueOfObjCType: @encode(unichar) at: &_thousandSeparator];
|
||||||
[decoder decodeValueOfObjCType: @encode(unichar) at: &_decimalSeparator];
|
[decoder decodeValueOfObjCType: @encode(unichar) at: &_decimalSeparator];
|
||||||
|
|
||||||
_roundingBehavior = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_roundingBehavior];
|
||||||
_maximum = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_maximum];
|
||||||
_minimum = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_minimum];
|
||||||
_attributedStringForNil = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_attributedStringForNil];
|
||||||
_attributedStringForNotANumber = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id)
|
||||||
_attributedStringForZero = RETAIN([decoder decodeObject]);
|
at: &_attributedStringForNotANumber];
|
||||||
_negativeFormat = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_attributedStringForZero];
|
||||||
_positiveFormat = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_negativeFormat];
|
||||||
_attributesForPositiveValues = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id) at: &_positiveFormat];
|
||||||
_attributesForNegativeValues = RETAIN([decoder decodeObject]);
|
[decoder decodeValueOfObjCType: @encode(id)
|
||||||
|
at: &_attributesForPositiveValues];
|
||||||
|
[decoder decodeValueOfObjCType: @encode(id)
|
||||||
|
at: &_attributesForNegativeValues];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
151
Source/NSValue.m
151
Source/NSValue.m
|
@ -68,6 +68,7 @@ static NSLock *placeholderLock;
|
||||||
if (self == [NSValue class])
|
if (self == [NSValue class])
|
||||||
{
|
{
|
||||||
abstractClass = self;
|
abstractClass = self;
|
||||||
|
[abstractClass setVersion: 1]; // Version 1
|
||||||
concreteClass = [GSValue class];
|
concreteClass = [GSValue class];
|
||||||
nonretainedObjectValueClass = [GSNonretainedObjectValue class];
|
nonretainedObjectValueClass = [GSNonretainedObjectValue class];
|
||||||
pointValueClass = [GSPointValue class];
|
pointValueClass = [GSPointValue class];
|
||||||
|
@ -381,33 +382,118 @@ static NSLock *placeholderLock;
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder *)coder
|
- (id) initWithCoder: (NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
char type[64];
|
||||||
const char *objctype;
|
const char *objctype;
|
||||||
Class c;
|
Class c;
|
||||||
id o;
|
id o;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
NSData *d;
|
int ver;
|
||||||
char *data;
|
|
||||||
unsigned cursor = 0;
|
|
||||||
|
|
||||||
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
objctype = (void*)NSZoneMalloc(NSDefaultMallocZone(), size);
|
/*
|
||||||
|
* For almost all type encodings, we can use space on the stack,
|
||||||
|
* but to handle exceptionally large ones (possibly some huge structs)
|
||||||
|
* we have a strategy of allocating and deallocating heap space too.
|
||||||
|
*/
|
||||||
|
if (size <= 64)
|
||||||
|
{
|
||||||
|
objctype = type;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
objctype = (void*)NSZoneMalloc(NSDefaultMallocZone(), size);
|
||||||
|
}
|
||||||
[coder decodeArrayOfObjCType: @encode(signed char)
|
[coder decodeArrayOfObjCType: @encode(signed char)
|
||||||
count: size
|
count: size
|
||||||
at: (void*)objctype];
|
at: (void*)objctype];
|
||||||
c = [abstractClass valueClassWithObjCType: objctype];
|
c = [abstractClass valueClassWithObjCType: objctype];
|
||||||
o = [c alloc];
|
o = [c allocWithZone: [coder objectZone]];
|
||||||
|
|
||||||
size = objc_sizeof_type(objctype);
|
ver = [coder versionForClassName: @"NSValue"];
|
||||||
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
if (ver < 1)
|
||||||
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
{
|
||||||
[d deserializeDataAt: data
|
if (c == pointValueClass)
|
||||||
ofObjCType: objctype
|
{
|
||||||
atCursor: &cursor
|
NSPoint v;
|
||||||
context: nil];
|
|
||||||
o = [o initWithBytes: data objCType: objctype];
|
[coder decodeValueOfObjCType: @encode(NSPoint) at: &v];
|
||||||
RELEASE(d);
|
o = [o initWithBytes: &v objCType: @encode(NSPoint)];
|
||||||
NSZoneFree(NSDefaultMallocZone(), data);
|
}
|
||||||
NSZoneFree(NSDefaultMallocZone(), (void*)objctype);
|
else if (c == sizeValueClass)
|
||||||
|
{
|
||||||
|
NSSize v;
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType: @encode(NSSize) at: &v];
|
||||||
|
o = [o initWithBytes: &v objCType: @encode(NSSize)];
|
||||||
|
}
|
||||||
|
else if (c == rangeValueClass)
|
||||||
|
{
|
||||||
|
NSRange v;
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType: @encode(NSRange) at: &v];
|
||||||
|
o = [o initWithBytes: &v objCType: @encode(NSRange)];
|
||||||
|
}
|
||||||
|
else if (c == rectValueClass)
|
||||||
|
{
|
||||||
|
NSRect v;
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType: @encode(NSRect) at: &v];
|
||||||
|
o = [o initWithBytes: &v objCType: @encode(NSRect)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned char *data;
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
|
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
||||||
|
[coder decodeArrayOfObjCType: @encode(unsigned char)
|
||||||
|
count: size
|
||||||
|
at: (void*)data];
|
||||||
|
o = [o initWithBytes: data objCType: objctype];
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSData *d;
|
||||||
|
unsigned cursor = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For performance, decode small values directly onto the stack,
|
||||||
|
* For larger values we allocate and deallocate heap space.
|
||||||
|
*/
|
||||||
|
size = objc_sizeof_type(objctype);
|
||||||
|
if (size <= 64)
|
||||||
|
{
|
||||||
|
unsigned char data[size];
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
||||||
|
[d deserializeDataAt: data
|
||||||
|
ofObjCType: objctype
|
||||||
|
atCursor: &cursor
|
||||||
|
context: nil];
|
||||||
|
o = [o initWithBytes: data objCType: objctype];
|
||||||
|
RELEASE(d);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned char *data;
|
||||||
|
|
||||||
|
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
||||||
|
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
||||||
|
[d deserializeDataAt: data
|
||||||
|
ofObjCType: objctype
|
||||||
|
atCursor: &cursor
|
||||||
|
context: nil];
|
||||||
|
o = [o initWithBytes: data objCType: objctype];
|
||||||
|
RELEASE(d);
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (objctype != type)
|
||||||
|
{
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), (void*)objctype);
|
||||||
|
}
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
self = o;
|
self = o;
|
||||||
return self;
|
return self;
|
||||||
|
@ -436,39 +522,6 @@ static NSLock *placeholderLock;
|
||||||
format: @"attempt to use uninitialised value"];
|
format: @"attempt to use uninitialised value"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder *)coder
|
|
||||||
{
|
|
||||||
const char *objctype;
|
|
||||||
Class c;
|
|
||||||
id o;
|
|
||||||
unsigned size;
|
|
||||||
NSData *d;
|
|
||||||
char *data;
|
|
||||||
unsigned cursor = 0;
|
|
||||||
|
|
||||||
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
|
||||||
objctype = (void*)NSZoneMalloc(NSDefaultMallocZone(), size);
|
|
||||||
[coder decodeArrayOfObjCType: @encode(signed char)
|
|
||||||
count: size
|
|
||||||
at: (void*)objctype];
|
|
||||||
c = [abstractClass valueClassWithObjCType: objctype];
|
|
||||||
o = [c alloc];
|
|
||||||
|
|
||||||
size = objc_sizeof_type(objctype);
|
|
||||||
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
|
||||||
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
|
||||||
[d deserializeDataAt: data
|
|
||||||
ofObjCType: objctype
|
|
||||||
atCursor: &cursor
|
|
||||||
context: nil];
|
|
||||||
o = [o initWithBytes: data objCType: objctype];
|
|
||||||
RELEASE(d);
|
|
||||||
NSZoneFree(NSDefaultMallocZone(), data);
|
|
||||||
NSZoneFree(NSDefaultMallocZone(), (void*)objctype);
|
|
||||||
self = o;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithBytes: (const void*)data objCType: (const char*)type
|
- (id) initWithBytes: (const void*)data objCType: (const char*)type
|
||||||
{
|
{
|
||||||
Class c = [abstractClass valueClassWithObjCType: type];
|
Class c = [abstractClass valueClassWithObjCType: type];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue