lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [2/3] git commit: refs/heads/sortex_ptr_only - Move Shrink() up from PostingPool to SortExternal.
Date Wed, 09 Jan 2013 02:14:07 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/522a9f4f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/522a9f4f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/522a9f4f

Branch: refs/heads/sortex_ptr_only
Commit: 522a9f4f790ce23fafd03968f21af08c29ac2ec8
Parents: f988948
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Jan 8 17:59:56 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Jan 8 17:59:56 2013 -0800

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c   |   29 -----------------------------
 core/Lucy/Index/PostingPool.cfh |    5 -----
 core/Lucy/Util/SortExternal.c   |   31 +++++++++++++++++++++++++++++++
 core/Lucy/Util/SortExternal.cfh |    5 +++++
 4 files changed, 36 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/522a9f4f/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 4895c6b..1092310 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -252,35 +252,6 @@ PostPool_add_segment(PostingPool *self, SegReader *reader, I32Array *doc_map,
 }
 
 void
-PostPool_shrink(PostingPool *self) {
-    if (self->cache_max - self->cache_tick > 0) {
-        size_t cache_count = PostPool_Cache_Count(self);
-        size_t size        = cache_count * sizeof(Obj*);
-        if (self->cache_tick > 0) {
-            Obj **start = self->cache + self->cache_tick;
-            memmove(self->cache, start, size);
-        }
-        self->cache      = (Obj**)REALLOCATE(self->cache, size);
-        self->cache_tick = 0;
-        self->cache_max  = cache_count;
-        self->cache_cap  = cache_count;
-    }
-    else {
-        FREEMEM(self->cache);
-        self->cache      = NULL;
-        self->cache_tick = 0;
-        self->cache_max  = 0;
-        self->cache_cap  = 0;
-    }
-    self->scratch_cap = 0;
-    FREEMEM(self->scratch);
-    self->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(PostingPool *self) {
     // Don't add a run unless we have data to put in it.
     if (PostPool_Cache_Count(self) == 0) { return; }

http://git-wip-us.apache.org/repos/asf/lucy/blob/522a9f4f/core/Lucy/Index/PostingPool.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.cfh b/core/Lucy/Index/PostingPool.cfh
index b4f2614..aaa7748 100644
--- a/core/Lucy/Index/PostingPool.cfh
+++ b/core/Lucy/Index/PostingPool.cfh
@@ -69,11 +69,6 @@ class Lucy::Index::PostingPool cnick 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/522a9f4f/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index ba23c47..1e7e143 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -154,6 +154,37 @@ SortEx_add_run(SortExternal *self, SortExternal *run) {
                              num_runs * sizeof(Obj**));
 }
 
+void
+SortEx_shrink(SortExternal *self) {
+    if (self->cache_max - self->cache_tick > 0) {
+        size_t cache_count = SortEx_Cache_Count(self);
+        size_t size        = cache_count * sizeof(Obj*);
+        if (self->cache_tick > 0) {
+            Obj **start = self->cache + self->cache_tick;
+            memmove(self->cache, start, size);
+        }
+        self->cache      = (Obj**)REALLOCATE(self->cache, size);
+        self->cache_tick = 0;
+        self->cache_max  = cache_count;
+        self->cache_cap  = cache_count;
+    }
+    else {
+        FREEMEM(self->cache);
+        self->cache      = NULL;
+        self->cache_tick = 0;
+        self->cache_max  = 0;
+        self->cache_cap  = 0;
+    }
+    self->scratch_cap = 0;
+    FREEMEM(self->scratch);
+    self->scratch = NULL;
+
+    for (uint32_t i = 0, max = VA_Get_Size(self->runs); i < max; i++) {
+        SortExternal *run = (SortExternal*)VA_Fetch(self->runs, i);
+        SortEx_Shrink(run);
+    }
+}
+
 static void
 S_refill_cache(SortExternal *self) {
     // Reset cache vars.

http://git-wip-us.apache.org/repos/asf/lucy/blob/522a9f4f/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 99c4bf1..d04f7e4 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -106,6 +106,11 @@ abstract class Lucy::Util::SortExternal cnick 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