mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Memory usage improvement
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8388 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fee923500f
commit
93f2ce7a6b
2 changed files with 20 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
|||
2000-12-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/GSIMap.h: On initialisation set number of nodes
|
||||
to exactly equal capacity, for improved memory efficiency.
|
||||
|
||||
2000-12-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSGAttributedString.m: Fix logic errors setting attributes.
|
||||
|
|
|
@ -335,7 +335,7 @@ GSIMapRemangleBuckets(GSIMapTable map,
|
|||
}
|
||||
|
||||
static INLINE void
|
||||
GSIMapMoreNodes(GSIMapTable map)
|
||||
GSIMapMoreNodes(GSIMapTable map, unsigned required)
|
||||
{
|
||||
GSIMapNode *newArray;
|
||||
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
|
||||
|
@ -357,20 +357,27 @@ GSIMapMoreNodes(GSIMapTable map)
|
|||
size_t chunkCount;
|
||||
size_t chunkSize;
|
||||
|
||||
memcpy(newArray,map->nodeChunks,(map->chunkCount)*sizeof(GSIMapNode));
|
||||
memcpy(newArray, map->nodeChunks, (map->chunkCount)*sizeof(GSIMapNode));
|
||||
if (map->nodeChunks != 0)
|
||||
{
|
||||
NSZoneFree(map->zone, map->nodeChunks);
|
||||
}
|
||||
map->nodeChunks = newArray;
|
||||
|
||||
if (map->chunkCount == 0)
|
||||
if (required == 0)
|
||||
{
|
||||
chunkCount = map->bucketCount > 1 ? map->bucketCount : 2;
|
||||
if (map->chunkCount == 0)
|
||||
{
|
||||
chunkCount = map->bucketCount > 1 ? map->bucketCount : 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkCount = ((map->nodeCount>>2)+1)<<1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chunkCount = ((map->nodeCount>>2)+1)<<1;
|
||||
chunkCount = required;
|
||||
}
|
||||
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
||||
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
||||
|
@ -395,7 +402,7 @@ GSIMapNewNode(GSIMapTable map, GSIMapKey key, GSIMapVal value)
|
|||
|
||||
if (node == 0)
|
||||
{
|
||||
GSIMapMoreNodes(map);
|
||||
GSIMapMoreNodes(map, 0);
|
||||
node = map->freeNodes;
|
||||
if (node == 0)
|
||||
{
|
||||
|
@ -419,7 +426,7 @@ GSIMapNewNode(GSIMapTable map, GSIMapKey key)
|
|||
|
||||
if (node == 0)
|
||||
{
|
||||
GSIMapMoreNodes(map);
|
||||
GSIMapMoreNodes(map, 0);
|
||||
node = map->freeNodes;
|
||||
if (node == 0)
|
||||
{
|
||||
|
@ -746,6 +753,6 @@ GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
|
|||
map->freeNodes = 0;
|
||||
map->chunkCount = 0;
|
||||
GSIMapRightSizeMap(map, capacity);
|
||||
GSIMapMoreNodes(map);
|
||||
GSIMapMoreNodes(map, capacity);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue