Author: rfm
Date: Thu Jul 16 11:59:22 2015
New Revision: 38806

URL: http://svn.gna.org/viewcvs/gnustep?rev=38806&view=rev
Log:
fix size of cache reporting

Modified:
    libs/performance/trunk/GSCache.h
    libs/performance/trunk/GSCache.m

Modified: libs/performance/trunk/GSCache.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSCache.h?rev=38806&r1=38805&r2=38806&view=diff
==============================================================================
--- libs/performance/trunk/GSCache.h    (original)
+++ libs/performance/trunk/GSCache.h    Thu Jul 16 11:59:22 2015
@@ -86,7 +86,12 @@
 - (unsigned) currentObjects;
 
 /**
- * Return the total size of the objects currently in the cache.
+ * Return the total size of the objects currently in the cache.<br />
+ * NB.  Object sizes are considered independently ... so where cached
+ * objects are containers with common content, the size of the cache
+ * may appear larger than is actually used.<br />
+ * Also, this figure does not consider memmory used by the cache itself
+ * or by the keys, only the memory used by the objects cached.
  */
 - (NSUInteger) currentSize;
 

Modified: libs/performance/trunk/GSCache.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSCache.m?rev=38806&r1=38805&r2=38806&view=diff
==============================================================================
--- libs/performance/trunk/GSCache.m    (original)
+++ libs/performance/trunk/GSCache.m    Thu Jul 16 11:59:22 2015
@@ -244,36 +244,7 @@
 
 - (NSUInteger) currentSize
 {
-  NSUInteger            size = 0;
-  NSMapEnumerator      e;
-  GSCacheItem          *i;
-  id                   k;
-
-  [my->lock lock];
-  if (nil == my->exclude)
-    {
-      my->exclude = NSCreateHashTable(NSNonOwnedPointerHashCallBacks, 0);
-    }
-  else
-    {
-      [my->exclude removeAllObjects];
-    }
-  e = NSEnumerateMapTable(my->contents);
-  while (NSNextMapEnumeratorPair(&e, (void**)&k, (void**)&i) != 0)
-    {
-      size += [i->object sizeInBytesExcluding: my->exclude];
-    }
-  NSEndMapTableEnumeration(&e);
-  if (my->maxSize > 0)
-    {
-      my->currentSize = size;
-    }
-  else
-    {
-      DESTROY(my->exclude);
-    }
-  [my->lock unlock];
-  return size;
+  return my->currentSize;
 }
 
 - (void) dealloc
@@ -619,7 +590,7 @@
       id               k;
       NSUInteger       size = 0;
 
-      if (my->exclude == nil)
+      if (nil == my->exclude)
        {
          my->exclude
             = NSCreateHashTable(NSNonOwnedPointerHashCallBacks, 0);
@@ -628,8 +599,8 @@
        {
          if (i->size == 0)
            {
+             i->size = [i->object sizeInBytesExcluding: my->exclude];
              [my->exclude removeAllObjects];
-             i->size = [i->object sizeInBytesExcluding: my->exclude];
            }
          if (i->size > max)
            {
@@ -703,13 +674,13 @@
     {
       if (maxSize > 0)
        {
-          if (my->exclude == nil)
+          if (nil == my->exclude)
             {
               my->exclude
                 = NSCreateHashTable(NSNonOwnedPointerHashCallBacks, 0);
             }
+         addSize = [anObject sizeInBytesExcluding: my->exclude];
          [my->exclude removeAllObjects];
-         addSize = [anObject sizeInBytesExcluding: my->exclude];
          if (addSize > maxSize)
            {
              addObjects = 0;   // Object too big to cache.
@@ -807,8 +778,10 @@
 
 - (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
 {
-  NSUInteger    size = [super sizeInBytesExcluding: exclude];
-
+  NSUInteger    size;
+
+  [my->lock lock];
+  size = [super sizeInBytesExcluding: exclude];
   if (size > 0)
     {
       size += sizeof(Item)
@@ -817,6 +790,7 @@
         + [my->name sizeInBytesExcluding: exclude]
         + [my->lock sizeInBytesExcluding: exclude];
     }
+  [my->lock unlock];
   return size;
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to