lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [15/20] git commit: refs/heads/cfish-string-prep1 - Convert Store::SharedLock to StringIterator
Date Sat, 07 Sep 2013 16:53:36 GMT
Convert Store::SharedLock to StringIterator


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

Branch: refs/heads/cfish-string-prep1
Commit: 430ba969d64f96003ba6f16cc1be011e0076b785
Parents: 07945bd
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Sep 7 16:56:44 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Store/SharedLock.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/430ba969/core/Lucy/Store/SharedLock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/SharedLock.c b/core/Lucy/Store/SharedLock.c
index a49b661..7ff1fc6 100644
--- a/core/Lucy/Store/SharedLock.c
+++ b/core/Lucy/Store/SharedLock.c
@@ -138,22 +138,30 @@ ShLock_Is_Locked_IMP(SharedLock *self) {
     while (DH_Next(dh)) {
         String *entry = DH_Get_Entry(dh);
         // Translation:  $locked = 1 if $entry =~ /^\Q$name-\d+\.lock$/
-        if (Str_Starts_With(entry, ivars->name)
-            && Str_Ends_With_Str(entry, ".lock", 5)
-           ) {
-            StackString *scratch = SSTR_WRAP(entry);
-            SStr_Chop(scratch, sizeof(".lock") - 1);
-            while (isdigit(SStr_Code_Point_From(scratch, 1))) {
-                SStr_Chop(scratch, 1);
-            }
-            if (SStr_Code_Point_From(scratch, 1) == '-') {
-                SStr_Chop(scratch, 1);
-                if (SStr_Equals(scratch, (Obj*)ivars->name)) {
-                    DECREF(entry);
-                    DECREF(dh);
-                    return true;
+        if (Str_Starts_With(entry, ivars->name)) {
+            StringIterator *iter = Str_Top(entry);
+            StrIter_Advance(iter, Str_Length(ivars->name));
+            uint32_t code_point = StrIter_Next(iter);
+            if (code_point == '-') {
+                code_point = StrIter_Next(iter);
+                if (code_point != STRITER_DONE && isdigit(code_point)) {
+                    while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+                        if (!isdigit(code_point)) { break; }
+                    }
+                    if (code_point == '.'
+                        && StrIter_Starts_With_UTF8(iter, "lock", 4)
+                    ) {
+                        StrIter_Advance(iter, 4);
+                        if (!StrIter_Has_Next(iter)) {
+                            DECREF(iter);
+                            DECREF(entry);
+                            DECREF(dh);
+                            return true;
+                        }
+                    }
                 }
             }
+            DECREF(iter);
         }
         DECREF(entry);
     }


Mime
View raw message