lucy-commits mailing list archives

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


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

Branch: refs/heads/cfish-string-prep1
Commit: a3d2e27cb52346b30b630be93f589d91e814d485
Parents: a0efa07
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Sep 7 15:59:03 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Store/Folder.c | 51 ++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/a3d2e27c/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index 4a97db2..066d20e 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -423,30 +423,28 @@ Folder_Consolidate_IMP(Folder *self, const String *path) {
 }
 
 static Folder*
-S_enclosing_folder(Folder *self, StackString *path) {
-    size_t path_component_len = 0;
+S_enclosing_folder(Folder *self, StringIterator *path) {
     uint32_t code_point;
 
-    // Strip trailing slash.
-    if (SStr_Code_Point_From(path, 0) == '/') { SStr_Chop(path, 1); }
-
     // Find first component of the file path.
-    StackString *scratch        = SSTR_WRAP((String*)path);
-    StackString *path_component = SSTR_WRAP((String*)path);
-    while (0 != (code_point = SStr_Nibble(scratch))) {
-        if (code_point == '/') {
-            SStr_Truncate(path_component, path_component_len);
-            SStr_Nip(path, path_component_len + 1);
+    String *path_component = NULL;
+    StringIterator *iter = StrIter_Clone(path);
+    while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+        if (code_point == '/' && StrIter_Has_Next(iter)) {
+            StrIter_Recede(iter, 1);
+            path_component = StrIter_substring(path, iter);
+            StrIter_Advance(iter, 1);
+            StrIter_Assign(path, iter);
             break;
         }
-        path_component_len++;
     }
+    DECREF(iter);
 
     // If we've eaten up the entire filepath, self is enclosing folder.
-    if (SStr_Get_Size(scratch) == 0) { return self; }
+    if (!path_component) { return self; }
 
-    Folder *local_folder
-        = Folder_Local_Find_Folder(self, (String*)path_component);
+    Folder *local_folder = Folder_Local_Find_Folder(self, path_component);
+    DECREF(path_component);
     if (!local_folder) {
         /* This element of the filepath doesn't exist, or it's not a
          * directory.  However, there are filepath characters left over,
@@ -461,8 +459,10 @@ S_enclosing_folder(Folder *self, StackString *path) {
 
 Folder*
 Folder_Enclosing_Folder_IMP(Folder *self, const String *path) {
-    StackString *scratch = SSTR_WRAP(path);
-    return S_enclosing_folder(self, scratch);
+    StringIterator *iter = Str_Top(path);
+    Folder *folder = S_enclosing_folder(self, iter);
+    DECREF(iter);
+    return folder;
 }
 
 Folder*
@@ -471,15 +471,16 @@ Folder_Find_Folder_IMP(Folder *self, const String *path) {
         return self;
     }
     else {
-        StackString *scratch = SSTR_WRAP(path);
-        Folder *enclosing_folder = S_enclosing_folder(self, scratch);
-        if (!enclosing_folder) {
-            return NULL;
-        }
-        else {
-            return Folder_Local_Find_Folder(enclosing_folder,
-                                            (String*)scratch);
+        Folder *folder = NULL;
+        StringIterator *iter = Str_Top(path);
+        Folder *enclosing_folder = S_enclosing_folder(self, iter);
+        if (enclosing_folder) {
+            String *folder_name = StrIter_substring(iter, NULL);
+            folder = Folder_Local_Find_Folder(enclosing_folder, folder_name);
+            DECREF(folder_name);
         }
+        DECREF(iter);
+        return folder;
     }
 }
 


Mime
View raw message