lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [49/54] [abbrv] git commit: refs/heads/sortex_ptr_only - Move Shrink() up from PostingPool to SortExternal.
Date Sat, 26 Apr 2014 23:12:19 GMT
Move Shrink() up from PostingPool to SortExternal.

Move the Shrink method up into the parent class and generalize it by
calling Shrink() on runs.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/7677ad4d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/7677ad4d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/7677ad4d

Branch: refs/heads/sortex_ptr_only
Commit: 7677ad4df614d0523571811dc4a9bf1f41e1df60
Parents: 88271ce
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Jan 8 17:59:56 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Apr 26 14:16:05 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c   | 30 ------------------------------
 core/Lucy/Index/PostingPool.cfh |  5 -----
 core/Lucy/Util/SortExternal.c   | 32 ++++++++++++++++++++++++++++++++
 core/Lucy/Util/SortExternal.cfh |  5 +++++
 4 files changed, 37 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 55eecc9..cc56c34 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -260,36 +260,6 @@ PostPool_Add_Segment_IMP(PostingPool *self, SegReader *reader,
 }
 
 void
-PostPool_Shrink_IMP(PostingPool *self) {
-    PostingPoolIVARS *const ivars = PostPool_IVARS(self);
-    if (ivars->cache_max - ivars->cache_tick > 0) {
-        size_t cache_count = PostPool_Cache_Count(self);
-        size_t size        = cache_count * sizeof(Obj*);
-        if (ivars->cache_tick > 0) {
-            Obj **start = ivars->cache + ivars->cache_tick;
-            memmove(ivars->cache, start, size);
-        }
-        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
-        ivars->cache_tick = 0;
-        ivars->cache_max  = cache_count;
-        ivars->cache_cap  = cache_count;
-    }
-    else {
-        FREEMEM(ivars->cache);
-        ivars->cache      = NULL;
-        ivars->cache_tick = 0;
-        ivars->cache_max  = 0;
-        ivars->cache_cap  = 0;
-    }
-    ivars->scratch_cap = 0;
-    FREEMEM(ivars->scratch);
-    ivars->scratch = NULL;
-
-    // It's not necessary to iterate over the runs, because they don't have
-    // any cache costs until Refill() gets called.
-}
-
-void
 PostPool_Flush_IMP(PostingPool *self) {
     PostingPoolIVARS *const ivars = PostPool_IVARS(self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Index/PostingPool.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.cfh b/core/Lucy/Index/PostingPool.cfh
index be1d26a..587955b 100644
--- a/core/Lucy/Index/PostingPool.cfh
+++ b/core/Lucy/Index/PostingPool.cfh
@@ -69,11 +69,6 @@ class Lucy::Index::PostingPool nickname PostPool
     Add_Inversion(PostingPool *self, Inversion *inversion, int32_t doc_id,
                   float doc_boost, float length_norm);
 
-    /** Reduce RAM footprint as much as possible.
-     */
-    void
-    Shrink(PostingPool *self);
-
     MemoryPool*
     Get_Mem_Pool(PostingPool *self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index c4d936e..f8a2690 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -165,6 +165,38 @@ SortEx_Add_Run_IMP(SortExternal *self, SortExternal *run) {
         = (Obj***)REALLOCATE(ivars->slice_starts, num_runs * sizeof(Obj**));
 }
 
+void
+SortEx_Shrink_IMP(SortExternal *self) {
+    SortExternalIVARS *const ivars = SortEx_IVARS(self);
+    if (ivars->cache_max - ivars->cache_tick > 0) {
+        size_t cache_count = SortEx_Cache_Count(self);
+        size_t size        = cache_count * sizeof(Obj*);
+        if (ivars->cache_tick > 0) {
+            Obj **start = ivars->cache + ivars->cache_tick;
+            memmove(ivars->cache, start, size);
+        }
+        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
+        ivars->cache_tick = 0;
+        ivars->cache_max  = cache_count;
+        ivars->cache_cap  = cache_count;
+    }
+    else {
+        FREEMEM(ivars->cache);
+        ivars->cache      = NULL;
+        ivars->cache_tick = 0;
+        ivars->cache_max  = 0;
+        ivars->cache_cap  = 0;
+    }
+    ivars->scratch_cap = 0;
+    FREEMEM(ivars->scratch);
+    ivars->scratch = NULL;
+
+    for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
+        SortExternal *run = (SortExternal*)VA_Fetch(ivars->runs, i);
+        SortEx_Shrink(run);
+    }
+}
+
 static void
 S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
     // Reset cache vars.

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 13d3009..cfc0591 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -106,6 +106,11 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     void
     Add_Run(SortExternal *self, decremented SortExternal *run);
 
+    /** Compact buffer sizes and minimize memory consumption.
+     */
+    void
+    Shrink(SortExternal *self);
+
     /** Refill the cache of a run.  Will only be called on child objects, not
      * the main object.
      */


Mime
View raw message