lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [40/54] [abbrv] git commit: refs/heads/sortex_ptr_only - Change SortFieldWriter to use pointer-sized elems.
Date Sat, 26 Apr 2014 23:12:10 GMT
Change SortFieldWriter to use pointer-sized elems.

SortFieldWriter is the only subclass of SortExternal where the elements
have been anything other than pointers.  By changing it to use pointers,
we enable subsequent commits simplifying SortExternal by limiting it to
sorting pointers only.


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

Branch: refs/heads/sortex_ptr_only
Commit: 0bf76df7e7bf07c4df35a3d68d7dc6da009bf7b5
Parents: e6d1963
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Jan 3 17:57:22 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Apr 26 09:52:20 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/SortFieldWriter.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/0bf76df7/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index e7d35cf..249e6ea 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, sizeof(SFWriterElem*));
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     ivars->null_ord        = -1;
     ivars->count           = 0;
@@ -139,6 +139,11 @@ SortFieldWriter_Clear_Cache_IMP(SortFieldWriter *self) {
     SortFieldWriter_Clear_Cache_t super_clear_cache
         = SUPER_METHOD_PTR(SORTFIELDWRITER, LUCY_SortFieldWriter_Clear_Cache);
     super_clear_cache(self);
+    // Note that we have not called MemPool_Release_All() on our memory pool.
+    // This is because the pool is shared amongst multiple SortFieldWriters
+    // which belong to a parent SortWriter; it is the responsibility of the
+    // parent SortWriter to release the memory pool once **all** of its child
+    // SortFieldWriters have cleared their caches.
 }
 
 void
@@ -191,9 +196,10 @@ SortFieldWriter_Add_IMP(SortFieldWriter *self, int32_t doc_id, Obj *value)
{
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
 
     // Uniq-ify the value, and record it for this document.
-    SFWriterElem elem;
-    elem.value = S_find_unique_value(ivars->uniq_vals, value);
-    elem.doc_id = doc_id;
+    SFWriterElem *elem
+        = (SFWriterElem*)MemPool_Grab(ivars->mem_pool, sizeof(SFWriterElem));
+    elem->value = S_find_unique_value(ivars->uniq_vals, value);
+    elem->doc_id = doc_id;
     SortFieldWriter_Feed(self, &elem);
     ivars->count++;
 }
@@ -336,8 +342,8 @@ S_write_val(Obj *val, int8_t prim_id, OutStream *ix_out, OutStream *dat_out,
 int
 SortFieldWriter_Compare_IMP(SortFieldWriter *self, void *va, void *vb) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
-    SFWriterElem *a = (SFWriterElem*)va;
-    SFWriterElem *b = (SFWriterElem*)vb;
+    SFWriterElem *a = *(SFWriterElem**)va;
+    SFWriterElem *b = *(SFWriterElem**)vb;
     int32_t comparison
         = FType_null_back_compare_values(ivars->type, a->value, b->value);
     if (comparison == 0) { comparison = b->doc_id - a->doc_id; }
@@ -553,7 +559,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
 
     // Grab the first item and record its ord.  Add a dummy ord for invalid
     // doc id 0.
-    SFWriterElem *elem = (SFWriterElem*)SortFieldWriter_Fetch(self);
+    SFWriterElem **elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self);
+    SFWriterElem *elem = *elem_ptr;
     ords[elem->doc_id] = ord;
     ords[0] = 0;
 
@@ -561,7 +568,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
     ivars->last_val = INCREF(elem->value);
     Obj *last_val_address = elem->value;
     S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
-    while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) {
+    while (NULL != (elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) {
+        elem = *elem_ptr;
         if (elem->value != last_val_address) {
             int32_t comparison
                 = FType_Compare_Values(ivars->type, elem->value, ivars->last_val);


Mime
View raw message