lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [10/50] [abbrv] git commit: refs/heads/master - Optimize Str_compare
Date Fri, 11 Oct 2013 13:31:48 GMT
Optimize Str_compare

UTF-8 strings can be (naively) compared using memcmp.


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

Branch: refs/heads/master
Commit: b0ddea3f35a6ff896f6a146a17bd2e4ee2e540ce
Parents: 38d5f9d
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Tue Sep 10 03:19:37 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Oct 11 15:28:15 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c | 31 ++++++++++++--------------
 1 file changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b0ddea3f/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 33074de..ef98320 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -425,26 +425,23 @@ int
 Str_compare(const void *va, const void *vb) {
     const String *a = *(const String**)va;
     const String *b = *(const String**)vb;
+    size_t min_size;
+    int    tie;
 
-    StackStringIterator *iter_a = STR_STACKTOP(a);
-    StackStringIterator *iter_b = STR_STACKTOP(b);
-
-    while (true) {
-        uint32_t code_point_a = SStrIter_Next(iter_a);
-        uint32_t code_point_b = SStrIter_Next(iter_b);
-
-        if (code_point_a == STRITER_DONE) {
-            return code_point_b == STRITER_DONE ? 0 : -1;
-        }
-        if (code_point_b == STRITER_DONE) {
-            return 1;
-        }
-        if (code_point_a != code_point_b) {
-            return code_point_a < code_point_b ? -1 : 1;
-        }
+    if (a->size <= b->size) {
+        min_size = a->size;
+        tie      = a->size < b->size ? -1 : 0;
+    }
+    else {
+        min_size = b->size;
+        tie      = 1;
     }
 
-    UNREACHABLE_RETURN(int);
+    int comparison = memcmp(a->ptr, b->ptr, min_size);
+    if (comparison < 0) { return -1; }
+    if (comparison > 0) { return 1; }
+
+    return tie;
 }
 
 bool


Mime
View raw message