Fixed error in growing strings - was overdoing it!

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4315 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-05-28 13:07:44 +00:00
parent 3f991f13a6
commit 43600b2156

View file

@ -780,9 +780,13 @@ typedef struct {
} NSGMutableCStringStruct; } NSGMutableCStringStruct;
static inline void static inline void
stringGrowBy(NSGMutableCStringStruct *self, unsigned size) stringGrowBy(NSGMutableCStringStruct *self, unsigned want)
{ {
self->_capacity = MAX(self->_capacity*2, self->_count+size+1); want += self->_count + 1;
if (want > self->_capacity)
self->_capacity += self->_capacity/2;
if (want > self->_capacity)
self->_capacity = want;
self->_contents_chars self->_contents_chars
= NSZoneRealloc(self->_zone, self->_contents_chars, self->_capacity); = NSZoneRealloc(self->_zone, self->_contents_chars, self->_capacity);
} }
@ -1011,7 +1015,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{ {
_capacity = length+1; _capacity = length+1;
_contents_chars = _contents_chars =
NSZoneRealloc(fastZone(self), _contents_chars, _capacity); NSZoneRealloc(_zone, _contents_chars, _capacity);
} }
[aString getCString: _contents_chars]; [aString getCString: _contents_chars];
_count = length; _count = length;
@ -1068,7 +1072,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{ {
_capacity *= 2; _capacity *= 2;
_contents_chars = _contents_chars =
NSZoneRealloc(fastZone(self), _contents_chars, _capacity); NSZoneRealloc(_zone, _contents_chars, _capacity);
} }
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, 1); stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, 1);
_contents_chars[index] = [newObject charValue]; _contents_chars[index] = [newObject charValue];
@ -1084,8 +1088,9 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{ {
char *ptr; char *ptr;
stringGrowBy((NSGMutableCStringStruct *)self, len); if (len > 0)
ptr = _contents_chars + _count; stringGrowBy((NSGMutableCStringStruct *)self, len);
ptr = &_contents_chars[_count];
_count += len; _count += len;
_hash = 0; _hash = 0;
return ptr; return ptr;