From 89f459748a62e04ea43d79a481a03ba6cb9b36be Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 26 Oct 1998 18:06:51 +0000 Subject: [PATCH] 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 --- Source/NSGCString.m | 18 ++++++++++------ Source/NSGString.m | 50 ++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Source/NSGCString.m b/Source/NSGCString.m index 6e71060ef..feed324b3 100644 --- a/Source/NSGCString.m +++ b/Source/NSGCString.m @@ -185,9 +185,12 @@ static IMP msInitImp; /* designated initialiser for mutable */ - (void) encodeWithCoder: aCoder { [aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count]; - [aCoder encodeArrayOfObjCType:@encode(unsigned char) - count:_count - at:_contents_chars]; + if (_count > 0) + { + [aCoder encodeArrayOfObjCType:@encode(unsigned char) + count:_count + at:_contents_chars]; + } } - initWithCoder: aCoder @@ -887,9 +890,12 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self, [aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap]; [self initWithCapacity:cap]; _count = cap; - [aCoder decodeArrayOfObjCType:@encode(unsigned char) - count:_count - at:_contents_chars]; + if (_count > 0) + { + [aCoder decodeArrayOfObjCType: @encode(unsigned char) + count: _count + at: _contents_chars]; + } return self; } diff --git a/Source/NSGString.m b/Source/NSGString.m index 4687d0870..e8600ca7d 100644 --- a/Source/NSGString.m +++ b/Source/NSGString.m @@ -265,21 +265,27 @@ - (void) encodeWithCoder: aCoder { - [aCoder encodeValueOfObjCType:@encode(int) at:&_count]; - [aCoder encodeArrayOfObjCType:@encode(unichar) - count:_count - at:_contents_chars]; + [aCoder encodeValueOfObjCType: @encode(unsigned) at: &_count]; + if (_count > 0) + { + [aCoder encodeArrayOfObjCType: @encode(unichar) + count: _count + at: _contents_chars]; + } } - initWithCoder: aCoder { - [aCoder decodeValueOfObjCType:@encode(int) at:&_count]; - _zone = fastZone(self); - _contents_chars = NSZoneMalloc(_zone, sizeof(unichar)*_count); - [aCoder decodeArrayOfObjCType:@encode(unichar) - count:_count - at:_contents_chars]; - return self; + [aCoder decodeValueOfObjCType: @encode(unsigned) at: &_count]; + if (_count) + { + _zone = fastZone(self); + _contents_chars = NSZoneMalloc(_zone, sizeof(unichar)*_count); + [aCoder decodeArrayOfObjCType: @encode(unichar) + count: _count + at: _contents_chars]; + } + return self; } @@ -548,25 +554,19 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self, 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 { unsigned cap; - [aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap]; + [aCoder decodeValueOfObjCType: @encode(unsigned) at: &cap]; [self initWithCapacity:cap]; - [aCoder decodeValueOfObjCType:@encode(int) at:&_count]; - [aCoder decodeArrayOfObjCType:@encode(unichar) - count:_count - at:_contents_chars]; + _count = cap; + if (_count) + { + [aCoder decodeArrayOfObjCType: @encode(unichar) + count: _count + at: _contents_chars]; + } return self; }