mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
c6e37f680b
commit
e7bbd6e347
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>
|
||||
|
||||
* Source/NSNumberFormatter.m (-initWithCoder:): decoded objects
|
||||
|
|
|
@ -155,13 +155,17 @@
|
|||
|
||||
- (id) init
|
||||
{
|
||||
id o;
|
||||
|
||||
_allowsFloats = YES;
|
||||
_decimalSeparator = '.';
|
||||
_thousandSeparator = ',';
|
||||
[self setAttributedStringForNil: AUTORELEASE([[NSAttributedString new]
|
||||
initWithString: @""])];
|
||||
[self setAttributedStringForNotANumber: AUTORELEASE([[NSAttributedString new]
|
||||
initWithString: @"NaN"])];
|
||||
o = [[NSAttributedString alloc] initWithString: @""];
|
||||
[self setAttributedStringForNil: o];
|
||||
RELEASE(o);
|
||||
o = [[NSAttributedString alloc] initWithString: @"NaN"];
|
||||
[self setAttributedStringForNotANumber: o];
|
||||
RELEASE(o);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -174,16 +178,19 @@
|
|||
[decoder decodeValueOfObjCType: @encode(unichar) at: &_thousandSeparator];
|
||||
[decoder decodeValueOfObjCType: @encode(unichar) at: &_decimalSeparator];
|
||||
|
||||
_roundingBehavior = RETAIN([decoder decodeObject]);
|
||||
_maximum = RETAIN([decoder decodeObject]);
|
||||
_minimum = RETAIN([decoder decodeObject]);
|
||||
_attributedStringForNil = RETAIN([decoder decodeObject]);
|
||||
_attributedStringForNotANumber = RETAIN([decoder decodeObject]);
|
||||
_attributedStringForZero = RETAIN([decoder decodeObject]);
|
||||
_negativeFormat = RETAIN([decoder decodeObject]);
|
||||
_positiveFormat = RETAIN([decoder decodeObject]);
|
||||
_attributesForPositiveValues = RETAIN([decoder decodeObject]);
|
||||
_attributesForNegativeValues = RETAIN([decoder decodeObject]);
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_roundingBehavior];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_maximum];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_minimum];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_attributedStringForNil];
|
||||
[decoder decodeValueOfObjCType: @encode(id)
|
||||
at: &_attributedStringForNotANumber];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_attributedStringForZero];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_negativeFormat];
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_positiveFormat];
|
||||
[decoder decodeValueOfObjCType: @encode(id)
|
||||
at: &_attributesForPositiveValues];
|
||||
[decoder decodeValueOfObjCType: @encode(id)
|
||||
at: &_attributesForNegativeValues];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
127
Source/NSValue.m
127
Source/NSValue.m
|
@ -68,6 +68,7 @@ static NSLock *placeholderLock;
|
|||
if (self == [NSValue class])
|
||||
{
|
||||
abstractClass = self;
|
||||
[abstractClass setVersion: 1]; // Version 1
|
||||
concreteClass = [GSValue class];
|
||||
nonretainedObjectValueClass = [GSNonretainedObjectValue class];
|
||||
pointValueClass = [GSPointValue class];
|
||||
|
@ -381,23 +382,103 @@ static NSLock *placeholderLock;
|
|||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
char type[64];
|
||||
const char *objctype;
|
||||
Class c;
|
||||
id o;
|
||||
unsigned size;
|
||||
NSData *d;
|
||||
char *data;
|
||||
unsigned cursor = 0;
|
||||
int ver;
|
||||
|
||||
[coder decodeValueOfObjCType: @encode(unsigned) at: &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)
|
||||
count: size
|
||||
at: (void*)objctype];
|
||||
c = [abstractClass valueClassWithObjCType: objctype];
|
||||
o = [c alloc];
|
||||
o = [c allocWithZone: [coder objectZone]];
|
||||
|
||||
ver = [coder versionForClassName: @"NSValue"];
|
||||
if (ver < 1)
|
||||
{
|
||||
if (c == pointValueClass)
|
||||
{
|
||||
NSPoint v;
|
||||
|
||||
[coder decodeValueOfObjCType: @encode(NSPoint) at: &v];
|
||||
o = [o initWithBytes: &v objCType: @encode(NSPoint)];
|
||||
}
|
||||
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
|
||||
|
@ -407,7 +488,12 @@ static NSLock *placeholderLock;
|
|||
o = [o initWithBytes: data objCType: objctype];
|
||||
RELEASE(d);
|
||||
NSZoneFree(NSDefaultMallocZone(), data);
|
||||
}
|
||||
}
|
||||
if (objctype != type)
|
||||
{
|
||||
NSZoneFree(NSDefaultMallocZone(), (void*)objctype);
|
||||
}
|
||||
RELEASE(self);
|
||||
self = o;
|
||||
return self;
|
||||
|
@ -436,39 +522,6 @@ static NSLock *placeholderLock;
|
|||
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
|
||||
{
|
||||
Class c = [abstractClass valueClassWithObjCType: type];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue