lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [09/17] git commit: refs/heads/cfish-string-prep1 - Make SortCache_Value work with immutable strings
Date Fri, 13 Sep 2013 18:31:41 GMT
Make SortCache_Value work with immutable strings


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

Branch: refs/heads/cfish-string-prep1
Commit: b7881f0e40bf6f5470c8314a5e6aa231817c4cde
Parents: eafb8f7
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Sep 9 21:15:52 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Sep 13 20:15:59 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Index/SortCache.c                    | 15 +-----
 core/Lucy/Index/SortCache.cfh                  | 15 ++----
 core/Lucy/Index/SortCache/NumericSortCache.c   | 52 +++++----------------
 core/Lucy/Index/SortCache/NumericSortCache.cfh | 28 ++++-------
 core/Lucy/Index/SortCache/TextSortCache.c      | 23 ++-------
 core/Lucy/Index/SortCache/TextSortCache.cfh    |  7 +--
 core/Lucy/Index/SortFieldWriter.c              |  8 ++--
 core/Lucy/Search/Collector/SortCollector.c     |  9 ++--
 core/Lucy/Search/RangeQuery.c                  | 10 ++--
 perl/buildlib/Lucy/Build/Binding/Index.pm      |  5 +-
 10 files changed, 46 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache.c b/core/Lucy/Index/SortCache.c
index 53f6d43..446ced2 100644
--- a/core/Lucy/Index/SortCache.c
+++ b/core/Lucy/Index/SortCache.c
@@ -111,22 +111,13 @@ SortCache_Find_IMP(SortCache *self, Obj *term) {
     int32_t          lo     = 0;
     int32_t          hi     = ivars->cardinality - 1;
     int32_t          result = -100;
-    Obj             *blank  = SortCache_Make_Blank(self);
-
-    if (term != NULL
-        && !Obj_Is_A(term, Obj_Get_VTable(blank))
-        && !Obj_Is_A(blank, Obj_Get_VTable(term))
-       ) {
-        THROW(ERR, "SortCache error for field %o: term is a %o, and not "
-              "comparable to a %o", ivars->field, Obj_Get_Class_Name(term),
-              Obj_Get_Class_Name(blank));
-    }
 
     // Binary search.
     while (hi >= lo) {
         const int32_t mid = lo + ((hi - lo) / 2);
-        Obj *val = SortCache_Value(self, mid, blank);
+        Obj *val = SortCache_Value(self, mid);
         int32_t comparison = FType_null_back_compare_values(type, term, val);
+        DECREF(val);
         if (comparison < 0) {
             hi = mid - 1;
         }
@@ -139,8 +130,6 @@ SortCache_Find_IMP(SortCache *self, Obj *term) {
         }
     }
 
-    DECREF(blank);
-
     if (hi < 0) {
         // Target is "less than" the first cache entry.
         return -1;

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache.cfh b/core/Lucy/Index/SortCache.cfh
index 9554425..f16b78f 100644
--- a/core/Lucy/Index/SortCache.cfh
+++ b/core/Lucy/Index/SortCache.cfh
@@ -34,18 +34,11 @@ class Lucy::Index::SortCache inherits Clownfish::Obj {
          void *ords, int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
          int32_t ord_width);
 
-    /** Assign the value for ordinal <code>ord</code> to <code>blank</code>.
-     *
-     * @return either <code>blank</code> (no longer blank), or NULL if the
-     * value for <code>ord</code> is NULL.
-     */
-    public abstract nullable Obj*
-    Value(SortCache *self, int32_t ord, Obj *blank);
-
-    /** Return an object appropriate for use as an argument to Value().
+    /** Return the value for ordinal <code>ord</code>, or NULL if the value
+     * for <code>ord</code> is NULL.
      */
-    public abstract incremented Obj*
-    Make_Blank(SortCache *self);
+    public abstract nullable incremented Obj*
+    Value(SortCache *self, int32_t ord);
 
     public void*
     Get_Ords(SortCache *self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache/NumericSortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/NumericSortCache.c b/core/Lucy/Index/SortCache/NumericSortCache.c
index 143c9c1..7241e6f 100644
--- a/core/Lucy/Index/SortCache/NumericSortCache.c
+++ b/core/Lucy/Index/SortCache/NumericSortCache.c
@@ -102,26 +102,19 @@ F64SortCache_init(Float64SortCache *self, const String *field,
 }
 
 Obj*
-F64SortCache_Value_IMP(Float64SortCache *self, int32_t ord, Obj *blank) {
+F64SortCache_Value_IMP(Float64SortCache *self, int32_t ord) {
     Float64SortCacheIVARS *const ivars = F64SortCache_IVARS(self);
     if (ord == ivars->null_ord) {
         return NULL;
     }
     else if (ord < 0) {
         THROW(ERR, "Ordinal less than 0 for %o: %i32", ivars->field, ord);
+        UNREACHABLE_RETURN(Obj*);
     }
     else {
-        Float64 *num_blank = (Float64*)CERTIFY(blank, FLOAT64);
         InStream_Seek(ivars->dat_in, ord * sizeof(double));
-        Float64_Set_Value(num_blank, InStream_Read_F64(ivars->dat_in));
+        return (Obj*)Float64_new(InStream_Read_F64(ivars->dat_in));
     }
-    return blank;
-}
-
-Float64*
-F64SortCache_Make_Blank_IMP(Float64SortCache *self) {
-    UNUSED_VAR(self);
-    return Float64_new(0.0);
 }
 
 /***************************************************************************/
@@ -147,26 +140,19 @@ F32SortCache_init(Float32SortCache *self, const String *field,
 }
 
 Obj*
-F32SortCache_Value_IMP(Float32SortCache *self, int32_t ord, Obj *blank) {
+F32SortCache_Value_IMP(Float32SortCache *self, int32_t ord) {
     Float32SortCacheIVARS *const ivars = F32SortCache_IVARS(self);
     if (ord == ivars->null_ord) {
         return NULL;
     }
     else if (ord < 0) {
         THROW(ERR, "Ordinal less than 0 for %o: %i32", ivars->field, ord);
+        UNREACHABLE_RETURN(Obj*);
     }
     else {
-        Float32 *num_blank = (Float32*)CERTIFY(blank, FLOAT32);
         InStream_Seek(ivars->dat_in, ord * sizeof(float));
-        Float32_Set_Value(num_blank, InStream_Read_F32(ivars->dat_in));
+        return (Obj*)Float32_new(InStream_Read_F32(ivars->dat_in));
     }
-    return blank;
-}
-
-Float32*
-F32SortCache_Make_Blank_IMP(Float32SortCache *self) {
-    UNUSED_VAR(self);
-    return Float32_new(0.0f);
 }
 
 /***************************************************************************/
@@ -192,26 +178,19 @@ I32SortCache_init(Int32SortCache *self, const String *field,
 }
 
 Obj*
-I32SortCache_Value_IMP(Int32SortCache *self, int32_t ord, Obj *blank) {
+I32SortCache_Value_IMP(Int32SortCache *self, int32_t ord) {
     Int32SortCacheIVARS *const ivars = I32SortCache_IVARS(self);
     if (ord == ivars->null_ord) {
         return NULL;
     }
     else if (ord < 0) {
         THROW(ERR, "Ordinal less than 0 for %o: %i32", ivars->field, ord);
+        UNREACHABLE_RETURN(Obj*);
     }
     else {
-        Integer32 *int_blank = (Integer32*)CERTIFY(blank, INTEGER32);
         InStream_Seek(ivars->dat_in, ord * sizeof(int32_t));
-        Int32_Set_Value(int_blank, InStream_Read_I32(ivars->dat_in));
+        return (Obj*)Int32_new(InStream_Read_I32(ivars->dat_in));
     }
-    return blank;
-}
-
-Integer32*
-I32SortCache_Make_Blank_IMP(Int32SortCache *self) {
-    UNUSED_VAR(self);
-    return Int32_new(0);
 }
 
 /***************************************************************************/
@@ -237,26 +216,19 @@ I64SortCache_init(Int64SortCache *self, const String *field,
 }
 
 Obj*
-I64SortCache_Value_IMP(Int64SortCache *self, int32_t ord, Obj *blank) {
+I64SortCache_Value_IMP(Int64SortCache *self, int32_t ord) {
     Int64SortCacheIVARS *const ivars = I64SortCache_IVARS(self);
     if (ord == ivars->null_ord) {
         return NULL;
     }
     else if (ord < 0) {
         THROW(ERR, "Ordinal less than 0 for %o: %i32", ivars->field, ord);
+        UNREACHABLE_RETURN(Obj*);
     }
     else {
-        Integer64 *int_blank = (Integer64*)CERTIFY(blank, INTEGER64);
         InStream_Seek(ivars->dat_in, ord * sizeof(int64_t));
-        Int64_Set_Value(int_blank, InStream_Read_I64(ivars->dat_in));
+        return (Obj*)Int64_new(InStream_Read_I64(ivars->dat_in));
     }
-    return blank;
-}
-
-Integer64*
-I64SortCache_Make_Blank_IMP(Int64SortCache *self) {
-    UNUSED_VAR(self);
-    return Int64_new(0);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache/NumericSortCache.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/NumericSortCache.cfh b/core/Lucy/Index/SortCache/NumericSortCache.cfh
index e1ba6e7..4b6de04 100644
--- a/core/Lucy/Index/SortCache/NumericSortCache.cfh
+++ b/core/Lucy/Index/SortCache/NumericSortCache.cfh
@@ -44,11 +44,8 @@ class Lucy::Index::SortCache::Float64SortCache cnick F64SortCache
          int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
          int32_t ord_width, InStream *ord_in, InStream *dat_in);
 
-    public nullable Obj*
-    Value(Float64SortCache *self, int32_t ord, Obj *blank);
-
-    public incremented Float64*
-    Make_Blank(Float64SortCache *self);
+    public nullable incremented Obj*
+    Value(Float64SortCache *self, int32_t ord);
 }
 
 class Lucy::Index::SortCache::Float32SortCache cnick F32SortCache
@@ -64,11 +61,8 @@ class Lucy::Index::SortCache::Float32SortCache cnick F32SortCache
          int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
          int32_t ord_width, InStream *ord_in, InStream *dat_in);
 
-    public nullable Obj*
-    Value(Float32SortCache *self, int32_t ord, Obj *blank);
-
-    public incremented Float32*
-    Make_Blank(Float32SortCache *self);
+    public nullable incremented Obj*
+    Value(Float32SortCache *self, int32_t ord);
 }
 
 class Lucy::Index::SortCache::Int32SortCache cnick I32SortCache
@@ -84,11 +78,8 @@ class Lucy::Index::SortCache::Int32SortCache cnick I32SortCache
          int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
          int32_t ord_width, InStream *ord_in, InStream *dat_in);
 
-    public nullable Obj*
-    Value(Int32SortCache *self, int32_t ord, Obj *blank);
-
-    public incremented Integer32*
-    Make_Blank(Int32SortCache *self);
+    public nullable incremented Obj*
+    Value(Int32SortCache *self, int32_t ord);
 }
 
 class Lucy::Index::SortCache::Int64SortCache cnick I64SortCache
@@ -104,11 +95,8 @@ class Lucy::Index::SortCache::Int64SortCache cnick I64SortCache
          int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
          int32_t ord_width, InStream *ord_in, InStream *dat_in);
 
-    public nullable Obj*
-    Value(Int64SortCache *self, int32_t ord, Obj *blank);
-
-    public incremented Integer64*
-    Make_Blank(Int64SortCache *self);
+    public nullable incremented Obj*
+    Value(Int64SortCache *self, int32_t ord);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache/TextSortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/TextSortCache.c b/core/Lucy/Index/SortCache/TextSortCache.c
index d9573f2..97df2bb 100644
--- a/core/Lucy/Index/SortCache/TextSortCache.c
+++ b/core/Lucy/Index/SortCache/TextSortCache.c
@@ -89,7 +89,7 @@ TextSortCache_Destroy_IMP(TextSortCache *self) {
 #define NULL_SENTINEL -1
 
 Obj*
-TextSortCache_Value_IMP(TextSortCache *self, int32_t ord, Obj *blank) {
+TextSortCache_Value_IMP(TextSortCache *self, int32_t ord) {
     TextSortCacheIVARS *const ivars = TextSortCache_IVARS(self);
     if (ord == ivars->null_ord) {
         return NULL;
@@ -110,26 +110,13 @@ TextSortCache_Value_IMP(TextSortCache *self, int32_t ord, Obj *blank)
{
         }
 
         // Read character data into String.
-        CERTIFY(blank, STRING);
-        int64_t len = next_offset - offset;
-        char *ptr = Str_Grow((String*)blank, (size_t)len);
+        size_t len = (size_t)(next_offset - offset);
+        char *ptr = (char*)MALLOCATE(len + 1);
         InStream_Seek(ivars->dat_in, offset);
-        InStream_Read_Bytes(ivars->dat_in, ptr, (size_t)len);
+        InStream_Read_Bytes(ivars->dat_in, ptr, len);
         ptr[len] = '\0';
-        if (!StrHelp_utf8_valid(ptr, (size_t)len)) {
-            Str_Set_Size((String*)blank, 0);
-            THROW(ERR, "Invalid UTF-8 at %i64 in %o", offset,
-                  InStream_Get_Filename(ivars->dat_in));
-        }
-        Str_Set_Size((String*)blank, (size_t)len);
+        return (Obj*)Str_new_steal_str(ptr, len, len + 1);
     }
-    return blank;
-}
-
-String*
-TextSortCache_Make_Blank_IMP(TextSortCache *self) {
-    UNUSED_VAR(self);
-    return Str_new_from_trusted_utf8("", 0);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortCache/TextSortCache.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/TextSortCache.cfh b/core/Lucy/Index/SortCache/TextSortCache.cfh
index 7fb4f12..66b73c1 100644
--- a/core/Lucy/Index/SortCache/TextSortCache.cfh
+++ b/core/Lucy/Index/SortCache/TextSortCache.cfh
@@ -36,11 +36,8 @@ class Lucy::Index::SortCache::TextSortCache
          int32_t ord_width, InStream *ord_in, InStream *ix_in,
          InStream *dat_in);
 
-    public nullable Obj*
-    Value(TextSortCache *self, int32_t ord, Obj *blank);
-
-    public incremented String*
-    Make_Blank(TextSortCache *self);
+    public nullable incremented Obj*
+    Value(TextSortCache *self, int32_t ord);
 
     public void
     Destroy(TextSortCache *self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 8c8e39b..b251123 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -436,14 +436,14 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
     Hash *const      uniq_vals  = ivars->uniq_vals;
     I32Array *const  doc_map    = ivars->doc_map;
     SortCache *const sort_cache = ivars->sort_cache;
-    Obj *const       blank      = SortCache_Make_Blank(sort_cache);
 
     while (ivars->run_ord < ivars->run_cardinality
            && MemPool_Get_Consumed(ivars->mem_pool) < ivars->mem_thresh
           ) {
-        Obj *val = SortCache_Value(sort_cache, ivars->run_ord, blank);
+        Obj *val = SortCache_Value(sort_cache, ivars->run_ord);
         if (val) {
             Hash_Store(uniq_vals, val, (Obj*)CFISH_TRUE);
+            DECREF(val);
             break;
         }
         ivars->run_ord++;
@@ -457,9 +457,10 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
                                ? I32Arr_Get(doc_map, raw_doc_id)
                                : raw_doc_id;
             if (remapped) {
-                Obj *val = SortCache_Value(sort_cache, ord, blank);
+                Obj *val = SortCache_Value(sort_cache, ord);
                 SortFieldWriter_Add(self, remapped, val);
                 count++;
+                DECREF(val);
             }
         }
         else if (ord > ivars->run_ord) {
@@ -475,7 +476,6 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
         ivars->sort_cache = NULL;
     }
 
-    DECREF(blank);
     return count;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Search/Collector/SortCollector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/Collector/SortCollector.c b/core/Lucy/Search/Collector/SortCollector.c
index 15e9480..4001b6b 100644
--- a/core/Lucy/Search/Collector/SortCollector.c
+++ b/core/Lucy/Search/Collector/SortCollector.c
@@ -295,15 +295,12 @@ SortColl_Collect_IMP(SortCollector *self, int32_t doc_id) {
 
             for (uint32_t i = 0, max = ivars->num_rules; i < max; i++) {
                 SortCache *cache   = ivars->sort_caches[i];
-                Obj       *old_val = (Obj*)VA_Delete(values, i);
+                Obj       *old_val = VA_Delete(values, i);
+                DECREF(old_val);
                 if (cache) {
                     int32_t ord = SortCache_Ordinal(cache, doc_id);
-                    Obj *blank = old_val
-                                 ? old_val
-                                 : SortCache_Make_Blank(cache);
-                    Obj *val = SortCache_Value(cache, ord, blank);
+                    Obj *val = SortCache_Value(cache, ord);
                     if (val) { VA_Store(values, i, (Obj*)val); }
-                    else     { DECREF(blank); }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/core/Lucy/Search/RangeQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/RangeQuery.c b/core/Lucy/Search/RangeQuery.c
index cbc5b74..a208213 100644
--- a/core/Lucy/Search/RangeQuery.c
+++ b/core/Lucy/Search/RangeQuery.c
@@ -279,8 +279,7 @@ S_find_lower_bound(RangeCompiler *self, SortCache *sort_cache) {
             lower_bound = 0;
         }
         else {
-            Obj *value = SortCache_Make_Blank(sort_cache);
-            Obj *low_found = SortCache_Value(sort_cache, low_ord, value);
+            Obj *low_found = SortCache_Value(sort_cache, low_ord);
             bool exact_match = low_found == NULL
                                  ? false
                                  : Obj_Equals(lower_term, low_found);
@@ -289,7 +288,7 @@ S_find_lower_bound(RangeCompiler *self, SortCache *sort_cache) {
             if (!exact_match || !RangeQuery_IVARS(parent)->include_lower) {
                 lower_bound++;
             }
-            DECREF(value);
+            DECREF(low_found);
         }
     }
 
@@ -309,8 +308,7 @@ S_find_upper_bound(RangeCompiler *self, SortCache *sort_cache) {
             retval = -1;
         }
         else {
-            Obj *value = SortCache_Make_Blank(sort_cache);
-            Obj *hi_found = SortCache_Value(sort_cache, hi_ord, value);
+            Obj *hi_found = SortCache_Value(sort_cache, hi_ord);
             bool exact_match = hi_found == NULL
                                  ? false
                                  : Obj_Equals(upper_term, (Obj*)hi_found);
@@ -319,7 +317,7 @@ S_find_upper_bound(RangeCompiler *self, SortCache *sort_cache) {
             if (exact_match && !RangeQuery_IVARS(parent)->include_upper) {
                 retval--;
             }
-            DECREF(value);
+            DECREF(hi_found);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b7881f0e/perl/buildlib/Lucy/Build/Binding/Index.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Index.pm b/perl/buildlib/Lucy/Build/Binding/Index.pm
index ac31d09..b02f299 100644
--- a/perl/buildlib/Lucy/Build/Binding/Index.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Index.pm
@@ -936,10 +936,9 @@ CODE:
         CFISH_RETHROW(CFISH_INCREF(cfish_Err_get_error()));
     }
     {
-        cfish_Obj *blank = LUCY_SortCache_Make_Blank(self);
-        cfish_Obj *value = LUCY_SortCache_Value(self, ord, blank);
+        cfish_Obj *value = LUCY_SortCache_Value(self, ord);
         RETVAL = XSBind_cfish_to_perl(value);
-        CFISH_DECREF(blank);
+        CFISH_DECREF(value);
     }
 }
 OUTPUT: RETVAL


Mime
View raw message