mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +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
c9ae445548
commit
36457b0023
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>
|
2000-12-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSGAttributedString.m: Fix logic errors setting attributes.
|
* Source/NSGAttributedString.m: Fix logic errors setting attributes.
|
||||||
|
|
|
@ -335,7 +335,7 @@ GSIMapRemangleBuckets(GSIMapTable map,
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void
|
static INLINE void
|
||||||
GSIMapMoreNodes(GSIMapTable map)
|
GSIMapMoreNodes(GSIMapTable map, unsigned required)
|
||||||
{
|
{
|
||||||
GSIMapNode *newArray;
|
GSIMapNode *newArray;
|
||||||
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
|
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
|
||||||
|
@ -357,20 +357,27 @@ GSIMapMoreNodes(GSIMapTable map)
|
||||||
size_t chunkCount;
|
size_t chunkCount;
|
||||||
size_t chunkSize;
|
size_t chunkSize;
|
||||||
|
|
||||||
memcpy(newArray,map->nodeChunks,(map->chunkCount)*sizeof(GSIMapNode));
|
memcpy(newArray, map->nodeChunks, (map->chunkCount)*sizeof(GSIMapNode));
|
||||||
if (map->nodeChunks != 0)
|
if (map->nodeChunks != 0)
|
||||||
{
|
{
|
||||||
NSZoneFree(map->zone, map->nodeChunks);
|
NSZoneFree(map->zone, map->nodeChunks);
|
||||||
}
|
}
|
||||||
map->nodeChunks = newArray;
|
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
|
else
|
||||||
{
|
{
|
||||||
chunkCount = ((map->nodeCount>>2)+1)<<1;
|
chunkCount = required;
|
||||||
}
|
}
|
||||||
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
||||||
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
||||||
|
@ -395,7 +402,7 @@ GSIMapNewNode(GSIMapTable map, GSIMapKey key, GSIMapVal value)
|
||||||
|
|
||||||
if (node == 0)
|
if (node == 0)
|
||||||
{
|
{
|
||||||
GSIMapMoreNodes(map);
|
GSIMapMoreNodes(map, 0);
|
||||||
node = map->freeNodes;
|
node = map->freeNodes;
|
||||||
if (node == 0)
|
if (node == 0)
|
||||||
{
|
{
|
||||||
|
@ -419,7 +426,7 @@ GSIMapNewNode(GSIMapTable map, GSIMapKey key)
|
||||||
|
|
||||||
if (node == 0)
|
if (node == 0)
|
||||||
{
|
{
|
||||||
GSIMapMoreNodes(map);
|
GSIMapMoreNodes(map, 0);
|
||||||
node = map->freeNodes;
|
node = map->freeNodes;
|
||||||
if (node == 0)
|
if (node == 0)
|
||||||
{
|
{
|
||||||
|
@ -746,6 +753,6 @@ GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
|
||||||
map->freeNodes = 0;
|
map->freeNodes = 0;
|
||||||
map->chunkCount = 0;
|
map->chunkCount = 0;
|
||||||
GSIMapRightSizeMap(map, capacity);
|
GSIMapRightSizeMap(map, capacity);
|
||||||
GSIMapMoreNodes(map);
|
GSIMapMoreNodes(map, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue