lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [41/54] [abbrv] git commit: refs/heads/sortex_ptr_only - Eliminate `width` member from SortExternal.
Date Sat, 26 Apr 2014 23:12:11 GMT
Eliminate `width` member from SortExternal.

Remove `width` as a constructor argument and member variable from
SortExternal and its subclasses, replacing it with hard-coded
"sizeof(Obj*)" as needed.


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

Branch: refs/heads/sortex_ptr_only
Commit: 8369f5f2a6732b32ff730e1f6f6c12b8065d72a5
Parents: 0bf76df
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Fri Jan 4 13:10:56 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Apr 26 10:19:34 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c     |  2 +-
 core/Lucy/Index/SortFieldWriter.c |  2 +-
 core/Lucy/Util/BBSortEx.c         |  5 ++--
 core/Lucy/Util/SortExternal.c     | 43 ++++++++++++++--------------------
 core/Lucy/Util/SortExternal.cfh   |  3 +--
 5 files changed, 24 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 6cf0d40..57067f2 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -76,7 +76,7 @@ PostPool_init(PostingPool *self, Schema *schema, Snapshot *snapshot,
               OutStream *lex_temp_out, OutStream *post_temp_out,
               OutStream *skip_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(Obj*));
+    SortEx_init((SortExternal*)self);
     PostingPoolIVARS *const ivars = PostPool_IVARS(self);
     ivars->doc_base         = 0;
     ivars->last_doc_id      = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 249e6ea..123e7f6 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -76,7 +76,7 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
                      OutStream *temp_ord_out, OutStream *temp_ix_out,
                      OutStream *temp_dat_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(SFWriterElem*));
+    SortEx_init((SortExternal*)self);
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     ivars->null_ord        = -1;
     ivars->count           = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 92d80a5..a0a0c7e 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -33,7 +33,7 @@ BBSortEx_new(uint32_t mem_threshold, VArray *external) {
 
 BBSortEx*
 BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) {
-    SortEx_init((SortExternal*)self, sizeof(Obj*));
+    SortEx_init((SortExternal*)self);
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
     ivars->external_tick = 0;
     ivars->external = (VArray*)INCREF(external);
@@ -133,7 +133,8 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
 
         if (ivars->cache_max == ivars->cache_cap) {
             BBSortEx_Grow_Cache(self,
-                                Memory_oversize(ivars->cache_max + 1, ivars->width));
+                                Memory_oversize(ivars->cache_max + 1,
+                                                sizeof(Obj*)));
         }
         Obj **cache = (Obj**)ivars->cache;
         cache[ivars->cache_max++] = INCREF(elem);

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index fc86556..b948131 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -41,12 +41,9 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
                   uint8_t *endpost);
 
 SortExternal*
-SortEx_init(SortExternal *self, size_t width) {
+SortEx_init(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    // Assign.
-    ivars->width        = width;
 
-    // Init.
     ivars->mem_thresh   = UINT32_MAX;
     ivars->cache        = NULL;
     ivars->cache_cap    = 0;
@@ -88,13 +85,12 @@ SortEx_Clear_Cache_IMP(SortExternal *self) {
 void
 SortEx_Feed_IMP(SortExternal *self, void *data) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    const size_t width = ivars->width;
     if (ivars->cache_max == ivars->cache_cap) {
-        size_t amount = Memory_oversize(ivars->cache_max + 1, width);
+        size_t amount = Memory_oversize(ivars->cache_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    uint8_t *target = ivars->cache + ivars->cache_max * width;
-    memcpy(target, data, width);
+    uint8_t *target = ivars->cache + ivars->cache_max * sizeof(Obj*);
+    memcpy(target, data, sizeof(Obj*));
     ivars->cache_max++;
 }
 
@@ -105,7 +101,7 @@ SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
     }
 
     if (ivars->cache_max > 0) {
-        return ivars->cache + ivars->cache_tick * ivars->width;
+        return ivars->cache + ivars->cache_tick * sizeof(Obj*);
     }
     else {
         return NULL;
@@ -140,10 +136,10 @@ SortEx_Sort_Cache_IMP(SortExternal *self) {
             ivars->scratch_cap = ivars->cache_cap;
             ivars->scratch
                 = (uint8_t*)REALLOCATE(ivars->scratch,
-                                       ivars->scratch_cap * ivars->width);
+                                       ivars->scratch_cap * sizeof(Obj*));
         }
         Sort_mergesort(ivars->cache, ivars->scratch, ivars->cache_max,
-                       ivars->width, compare, self);
+                       sizeof(Obj*), compare, self);
     }
 }
 
@@ -193,7 +189,6 @@ S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
 static uint8_t*
 S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
     uint8_t *endpost = NULL;
-    const size_t width = ivars->width;
 
     for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
         // Get a run and retrieve the last item in its cache.
@@ -207,7 +202,7 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            uint8_t *candidate = run_ivars->cache + tick * width;
+            uint8_t *candidate = run_ivars->cache + tick * sizeof(Obj*);
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -226,7 +221,6 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
 static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 uint8_t *endpost) {
-    size_t      width        = ivars->width;
     uint32_t    num_runs     = VA_Get_Size(ivars->runs);
     uint8_t   **slice_starts = ivars->slice_starts;
     uint32_t   *slice_sizes  = ivars->slice_sizes;
@@ -246,12 +240,12 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
             // Move slice content from run cache to main cache.
             if (ivars->cache_max + slice_size > ivars->cache_cap) {
                 size_t cap = Memory_oversize(ivars->cache_max + slice_size,
-                                             width);
+                                             sizeof(Obj*));
                 SortEx_Grow_Cache(self, cap);
             }
-            memcpy(ivars->cache + ivars->cache_max * width,
-                   run_ivars->cache + run_ivars->cache_tick * width,
-                   slice_size * width);
+            memcpy(ivars->cache + ivars->cache_max * sizeof(Obj*),
+                   run_ivars->cache + run_ivars->cache_tick * sizeof(Obj*),
+                   slice_size * sizeof(Obj*));
             run_ivars->cache_tick += slice_size;
             ivars->cache_max += slice_size;
 
@@ -263,7 +257,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < ivars->num_slices; i++) {
-        slice_starts[i] = ivars->cache + total * width;
+        slice_starts[i] = ivars->cache + total * sizeof(Obj*);
         total += slice_sizes[i];
     }
 
@@ -272,7 +266,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     if (ivars->scratch_cap < ivars->cache_cap) {
         ivars->scratch_cap = ivars->cache_cap;
         ivars->scratch = (uint8_t*)REALLOCATE(
-                            ivars->scratch, ivars->scratch_cap * width);
+                            ivars->scratch, ivars->scratch_cap * sizeof(Obj*));
     }
 
     // Exploit previous sorting, rather than sort cache naively.
@@ -287,10 +281,10 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 const uint32_t merged_size = slice_sizes[i] + slice_sizes[i + 1];
                 Sort_merge(slice_starts[i], slice_sizes[i],
                            slice_starts[i + 1], slice_sizes[i + 1], ivars->scratch,
-                           ivars->width, compare, self);
+                           sizeof(Obj*), compare, self);
                 slice_sizes[j]  = merged_size;
                 slice_starts[j] = slice_starts[i];
-                memcpy(slice_starts[j], ivars->scratch, merged_size * width);
+                memcpy(slice_starts[j], ivars->scratch, merged_size * sizeof(Obj*));
                 i += 2;
                 j += 1;
             }
@@ -312,7 +306,7 @@ void
 SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t size) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (size > ivars->cache_cap) {
-        ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size * ivars->width);
+        ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size * sizeof(Obj*));
         ivars->cache_cap = size;
     }
 }
@@ -323,14 +317,13 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
     int32_t          lo      = ivars->cache_tick - 1;
     int32_t          hi      = ivars->cache_max;
     uint8_t *const   cache   = ivars->cache;
-    const size_t     width   = ivars->width;
     SortEx_Compare_t compare
         = METHOD_PTR(SortEx_Get_VTable(self), LUCY_SortEx_Compare);
 
     // Binary search.
     while (hi - lo > 1) {
         const int32_t mid   = lo + ((hi - lo) / 2);
-        const int32_t delta = compare(self, cache + mid * width, endpost);
+        const int32_t delta = compare(self, cache + mid * sizeof(Obj*), endpost);
         if (delta > 0) { hi = mid; }
         else           { lo = mid; }
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index c414140..8362c4f 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -60,11 +60,10 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     uint8_t      **slice_starts;
     uint32_t      *slice_sizes;
     uint32_t       mem_thresh;
-    size_t         width;
     bool           flipped;
 
     inert SortExternal*
-    init(SortExternal *self, size_t width);
+    init(SortExternal *self);
 
     /** Compare two sortable elements.
      */


Mime
View raw message