Browse Source

Simplify ensure, remove need for doCacheAdd flag
Remove unused/unneeded remove() and clear()

Signed-off-by: Jake Smith <jake.smith@lexisnexis.com>

Jake Smith 11 years ago
parent
commit
a902493bcf
2 changed files with 12 additions and 50 deletions
  1. 12 47
      common/thorhelper/roxierow.cpp
  2. 0 3
      common/thorhelper/roxierow.hpp

+ 12 - 47
common/thorhelper/roxierow.cpp

@@ -417,49 +417,27 @@ public:
     {
         SpinBlock b(allAllocatorsLock);
         CAllocatorCacheItem *container = _lookup(meta, activityId, flags);
-        unsigned allocatorId;
-        bool doCacheAdd = true;
         if (container)
         {
             if (0 == (roxiemem::RHFunique & flags))
                 return LINK(&container->queryElement());
             // if in cache but unique, reuse allocatorId
-            allocatorId = container->queryAllocatorId();
-            doCacheAdd = false;
-        }
-        else
-        {
-            assertex(allAllocators.ordinality() < ALLOCATORID_MASK);
-            allocatorId = allAllocators.ordinality();
-            // NB: a RHFunique allocator, will cause 1st to be added to 'allAllocators'
-            // subsequent requests for the same type of unique allocator, will share same allocatorId
-            // resulting in the 1st allocator being reused by all instances for onDestroy() etc.
+            return callback->createAllocator(meta, activityId, container->queryAllocatorId(), flags);
         }
+        // NB: a RHFunique allocator, will cause 1st to be added to 'allAllocators'
+        // subsequent requests for the same type of unique allocator, will share same allocatorId
+        // resulting in the 1st allocator being reused by all instances for onDestroy() etc.
+
+        assertex(allAllocators.ordinality() < ALLOCATORID_MASK);
+        unsigned allocatorId = allAllocators.ordinality();
         IEngineRowAllocator *ret = callback->createAllocator(meta, activityId, allocatorId, flags);
-        if (doCacheAdd)
-        {
-            AllocatorKey key(meta, activityId, flags);
-            CAllocatorCacheItem *container = new CAllocatorCacheItem(LINK(ret), allocatorId, key);
-            cache.replace(*container);
-            allAllocators.append(*LINK(ret));
-        }
+        AllocatorKey key(meta, activityId, flags);
+        container = new CAllocatorCacheItem(LINK(ret), allocatorId, key);
+        cache.replace(*container);
+        allAllocators.append(*LINK(ret));
+
         return ret;
     }
-    virtual bool remove(IOutputMetaData *meta, unsigned activityId, roxiemem::RoxieHeapFlags flags)
-    {
-        SpinBlock b(allAllocatorsLock);
-        CAllocatorCacheItem *container = _lookup(meta, activityId, flags);
-        if (!container)
-            return false;
-        allAllocators.zap(container->queryElement());
-        return cache.removeExact(container);
-    }
-    virtual void clear()
-    {
-        SpinBlock b(allAllocatorsLock);
-        cache.kill();
-        allAllocators.kill();
-    }
     virtual unsigned items() const
     {
         return allAllocators.ordinality();
@@ -729,9 +707,6 @@ protected:
         }
         // test that 64 in cache
         ASSERT(allocatorCache->items() == 64);
-        // lookup one
-        Owned<IEngineRowAllocator> allocator = allocatorCache->lookup(&metas.item(0), 1, roxiemem::RHFnone);
-        ASSERT(NULL != allocator);
 
         // test ensure again
         for (unsigned fixedSize=1; fixedSize<=64; fixedSize++)
@@ -742,16 +717,6 @@ protected:
         }
         ASSERT(allocatorCache->items() == 64);
 
-        // remove all
-        for (unsigned fixedSize=1; fixedSize<=64; fixedSize++)
-        {
-            unsigned activityId = 1 + ((fixedSize-1) % 32); // i.e. make an id, so half are duplicates
-            IOutputMetaData *meta = &metas.item(fixedSize-1); // from 1st round
-            ASSERT(allocatorCache->remove(meta, activityId, roxiemem::RHFnone));
-        }
-        // test that all removed
-        ASSERT(allocatorCache->items() == 0);
-
         metas.kill();
         allocatorCache.clear();
     }

+ 0 - 3
common/thorhelper/roxierow.hpp

@@ -28,10 +28,7 @@ extern THORHELPER_API IEngineRowAllocator * createCrcRoxieRowAllocator(roxiemem:
 
 interface IRowAllocatorMetaActIdCache : extends roxiemem::IRowAllocatorCache
 {
-    virtual bool remove(IOutputMetaData *meta, unsigned activityId, roxiemem::RoxieHeapFlags flags) = 0;
-    virtual IEngineRowAllocator *lookup(IOutputMetaData *meta, unsigned activityId, roxiemem::RoxieHeapFlags flags) const = 0;
     virtual IEngineRowAllocator *ensure(IOutputMetaData * meta, unsigned activityId, roxiemem::RoxieHeapFlags flags) = 0;
-    virtual void clear() = 0;
     virtual unsigned items() const = 0;
 };