lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [1/3] git commit: refs/heads/sortex_ptr_only - Eliminate `width` member from SortExternal.
Date Fri, 04 Jan 2013 21:20:34 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/7310e770
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/7310e770
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/7310e770

Branch: refs/heads/sortex_ptr_only
Commit: 7310e7706c082b800fe2533f86b7a5d3bbcf4a94
Parents: d4b7bac
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Fri Jan 4 13:10:56 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Jan 4 13:12:59 2013 -0800

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


http://git-wip-us.apache.org/repos/asf/lucy/blob/7310e770/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index f2c1146..8a8cdd8 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -75,7 +75,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);
     self->doc_base         = 0;
     self->last_doc_id      = 0;
     self->doc_map          = NULL;

http://git-wip-us.apache.org/repos/asf/lucy/blob/7310e770/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 26fd197..461482f 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);
     self->null_ord        = -1;
     self->count           = 0;
     self->ord_start       = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/7310e770/core/Lucy/Test/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/BBSortEx.c b/core/Lucy/Test/Util/BBSortEx.c
index 9a68616..c47411d 100644
--- a/core/Lucy/Test/Util/BBSortEx.c
+++ b/core/Lucy/Test/Util/BBSortEx.c
@@ -32,7 +32,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);
     self->external_tick = 0;
     self->external = (VArray*)INCREF(external);
     self->mem_consumed = 0;
@@ -123,7 +123,8 @@ BBSortEx_refill(BBSortEx *self) {
 
         if (self->cache_max == self->cache_cap) {
             BBSortEx_Grow_Cache(self,
-                                Memory_oversize(self->cache_max + 1, self->width));
+                                Memory_oversize(self->cache_max + 1,
+                                                sizeof(Obj*)));
         }
         Obj **cache = (Obj**)self->cache;
         cache[self->cache_max++] = INCREF(elem);

http://git-wip-us.apache.org/repos/asf/lucy/blob/7310e770/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 4f530f7..d297d29 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -39,11 +39,7 @@ static uint32_t
 S_find_slice_size(SortExternal *self, uint8_t *endpost);
 
 SortExternal*
-SortEx_init(SortExternal *self, size_t width) {
-    // Assign.
-    self->width        = width;
-
-    // Init.
+SortEx_init(SortExternal *self) {
     self->mem_thresh   = UINT32_MAX;
     self->cache        = NULL;
     self->cache_cap    = 0;
@@ -82,13 +78,12 @@ SortEx_clear_cache(SortExternal *self) {
 
 void
 SortEx_feed(SortExternal *self, void *data) {
-    const size_t width = self->width;
     if (self->cache_max == self->cache_cap) {
-        size_t amount = Memory_oversize(self->cache_max + 1, width);
+        size_t amount = Memory_oversize(self->cache_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    uint8_t *target = self->cache + self->cache_max * width;
-    memcpy(target, data, width);
+    uint8_t *target = self->cache + self->cache_max * sizeof(Obj*);
+    memcpy(target, data, sizeof(Obj*));
     self->cache_max++;
 }
 
@@ -99,7 +94,7 @@ SI_peek(SortExternal *self) {
     }
 
     if (self->cache_max > 0) {
-        return self->cache + self->cache_tick * self->width;
+        return self->cache + self->cache_tick * sizeof(Obj*);
     }
     else {
         return NULL;
@@ -131,10 +126,10 @@ SortEx_sort_cache(SortExternal *self) {
             self->scratch_cap = self->cache_cap;
             self->scratch = (uint8_t*)REALLOCATE(
                                 self->scratch,
-                                self->scratch_cap * self->width);
+                                self->scratch_cap * sizeof(Obj*));
         }
         Sort_mergesort(self->cache, self->scratch, self->cache_max,
-                       self->width, compare, self);
+                       sizeof(Obj*), compare, self);
     }
 }
 
@@ -183,7 +178,6 @@ S_refill_cache(SortExternal *self) {
 static uint8_t*
 S_find_endpost(SortExternal *self) {
     uint8_t *endpost = NULL;
-    const size_t width = self->width;
 
     for (uint32_t i = 0, max = VA_Get_Size(self->runs); i < max; i++) {
         // Get a run and retrieve the last item in its cache.
@@ -196,7 +190,7 @@ S_find_endpost(SortExternal *self) {
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            uint8_t *candidate = run->cache + tick * width;
+            uint8_t *candidate = run->cache + tick * sizeof(Obj*);
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -214,7 +208,6 @@ S_find_endpost(SortExternal *self) {
 
 static void
 S_absorb_slices(SortExternal *self, uint8_t *endpost) {
-    size_t      width        = self->width;
     uint32_t    num_runs     = VA_Get_Size(self->runs);
     uint8_t   **slice_starts = self->slice_starts;
     uint32_t   *slice_sizes  = self->slice_sizes;
@@ -233,12 +226,12 @@ S_absorb_slices(SortExternal *self, uint8_t *endpost) {
             // Move slice content from run cache to main cache.
             if (self->cache_max + slice_size > self->cache_cap) {
                 size_t cap = Memory_oversize(self->cache_max + slice_size,
-                                             width);
+                                             sizeof(Obj*));
                 SortEx_Grow_Cache(self, cap);
             }
-            memcpy(self->cache + self->cache_max * width,
-                   run->cache + run->cache_tick * width,
-                   slice_size * width);
+            memcpy(self->cache + self->cache_max * sizeof(Obj*),
+                   run->cache + run->cache_tick * sizeof(Obj*),
+                   slice_size * sizeof(Obj*));
             run->cache_tick += slice_size;
             self->cache_max += slice_size;
 
@@ -250,7 +243,7 @@ S_absorb_slices(SortExternal *self, uint8_t *endpost) {
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < self->num_slices; i++) {
-        slice_starts[i] = self->cache + total * width;
+        slice_starts[i] = self->cache + total * sizeof(Obj*);
         total += slice_sizes[i];
     }
 
@@ -259,7 +252,7 @@ S_absorb_slices(SortExternal *self, uint8_t *endpost) {
     if (self->scratch_cap < self->cache_cap) {
         self->scratch_cap = self->cache_cap;
         self->scratch = (uint8_t*)REALLOCATE(
-                            self->scratch, self->scratch_cap * width);
+                            self->scratch, self->scratch_cap * sizeof(Obj*));
     }
 
     // Exploit previous sorting, rather than sort cache naively.
@@ -274,10 +267,10 @@ S_absorb_slices(SortExternal *self, uint8_t *endpost) {
                 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], self->scratch,
-                           self->width, compare, self);
+                           sizeof(Obj*), compare, self);
                 slice_sizes[j]  = merged_size;
                 slice_starts[j] = slice_starts[i];
-                memcpy(slice_starts[j], self->scratch, merged_size * width);
+                memcpy(slice_starts[j], self->scratch, merged_size * sizeof(Obj*));
                 i += 2;
                 j += 1;
             }
@@ -298,7 +291,7 @@ S_absorb_slices(SortExternal *self, uint8_t *endpost) {
 void
 SortEx_grow_cache(SortExternal *self, uint32_t size) {
     if (size > self->cache_cap) {
-        self->cache = (uint8_t*)REALLOCATE(self->cache, size * self->width);
+        self->cache = (uint8_t*)REALLOCATE(self->cache, size * sizeof(Obj*));
         self->cache_cap = size;
     }
 }
@@ -308,14 +301,13 @@ S_find_slice_size(SortExternal *self, uint8_t *endpost) {
     int32_t          lo      = self->cache_tick - 1;
     int32_t          hi      = self->cache_max;
     uint8_t *const   cache   = self->cache;
-    const size_t     width   = self->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/7310e770/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index cb5779e..0ea2b05 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -60,11 +60,10 @@ abstract class Lucy::Util::SortExternal cnick 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