Tidied coding/decoding to be a bit more efficient.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3120 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-26 18:06:51 +00:00
parent 0c5139b3a8
commit 37a94d8b42
2 changed files with 37 additions and 31 deletions

View file

@ -185,9 +185,12 @@ static IMP msInitImp; /* designated initialiser for mutable */
- (void) encodeWithCoder: aCoder - (void) encodeWithCoder: aCoder
{ {
[aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count]; [aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count];
[aCoder encodeArrayOfObjCType:@encode(unsigned char) if (_count > 0)
count:_count {
at:_contents_chars]; [aCoder encodeArrayOfObjCType:@encode(unsigned char)
count:_count
at:_contents_chars];
}
} }
- initWithCoder: aCoder - initWithCoder: aCoder
@ -887,9 +890,12 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
[aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap]; [aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap];
[self initWithCapacity:cap]; [self initWithCapacity:cap];
_count = cap; _count = cap;
[aCoder decodeArrayOfObjCType:@encode(unsigned char) if (_count > 0)
count:_count {
at:_contents_chars]; [aCoder decodeArrayOfObjCType: @encode(unsigned char)
count: _count
at: _contents_chars];
}
return self; return self;
} }

View file

@ -265,21 +265,27 @@
- (void) encodeWithCoder: aCoder - (void) encodeWithCoder: aCoder
{ {
[aCoder encodeValueOfObjCType:@encode(int) at:&_count]; [aCoder encodeValueOfObjCType: @encode(unsigned) at: &_count];
[aCoder encodeArrayOfObjCType:@encode(unichar) if (_count > 0)
count:_count {
at:_contents_chars]; [aCoder encodeArrayOfObjCType: @encode(unichar)
count: _count
at: _contents_chars];
}
} }
- initWithCoder: aCoder - initWithCoder: aCoder
{ {
[aCoder decodeValueOfObjCType:@encode(int) at:&_count]; [aCoder decodeValueOfObjCType: @encode(unsigned) at: &_count];
_zone = fastZone(self); if (_count)
_contents_chars = NSZoneMalloc(_zone, sizeof(unichar)*_count); {
[aCoder decodeArrayOfObjCType:@encode(unichar) _zone = fastZone(self);
count:_count _contents_chars = NSZoneMalloc(_zone, sizeof(unichar)*_count);
at:_contents_chars]; [aCoder decodeArrayOfObjCType: @encode(unichar)
return self; count: _count
at: _contents_chars];
}
return self;
} }
@ -548,25 +554,19 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
range.location, range.length); range.location, range.length);
} }
- (void) encodeWithCoder: aCoder // *** changed to unichar
{
[aCoder encodeValueOfObjCType:@encode(unsigned) at:&_capacity];
[aCoder encodeValueOfObjCType:@encode(int) at:&_count];
[aCoder encodeArrayOfObjCType:@encode(unichar)
count:_count
at:_contents_chars];
}
- initWithCoder: aCoder // *** changed to unichar - initWithCoder: aCoder // *** changed to unichar
{ {
unsigned cap; unsigned cap;
[aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap]; [aCoder decodeValueOfObjCType: @encode(unsigned) at: &cap];
[self initWithCapacity:cap]; [self initWithCapacity:cap];
[aCoder decodeValueOfObjCType:@encode(int) at:&_count]; _count = cap;
[aCoder decodeArrayOfObjCType:@encode(unichar) if (_count)
count:_count {
at:_contents_chars]; [aCoder decodeArrayOfObjCType: @encode(unichar)
count: _count
at: _contents_chars];
}
return self; return self;
} }