about summary refs log tree commit diff
path: root/users/zseri/store-ref-scanner
diff options
context:
space:
mode:
authorzseri <zseri.devel@ytrizja.de>2021-12-30T01·56+0100
committerzseri <zseri.devel@ytrizja.de>2021-12-30T02·00+0000
commit2f431bf8df1a2c4df15c48a94d117d41b0838c6b (patch)
tree75e743ddb3509f5b4cfa7157461c311b2f40a6b6 /users/zseri/store-ref-scanner
parentc3a9c90ccec637e48fbcb5f9e11158fe65019096 (diff)
refactor(zseri/s-r-sc): use inner while loop to improve perf r/3505
Change-Id: I13e95b91351af33c2452f1c4de45cc47aeae1dc0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4745
Tested-by: BuildkiteCI
Reviewed-by: zseri <zseri.devel@ytrizja.de>
Diffstat (limited to 'users/zseri/store-ref-scanner')
-rw-r--r--users/zseri/store-ref-scanner/src/lib.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/users/zseri/store-ref-scanner/src/lib.rs b/users/zseri/store-ref-scanner/src/lib.rs
index ae1912c555c6..0f86a769fe63 100644
--- a/users/zseri/store-ref-scanner/src/lib.rs
+++ b/users/zseri/store-ref-scanner/src/lib.rs
@@ -77,20 +77,21 @@ where
 
     fn next(&mut self) -> Option<Input> {
         let hbl: usize = self.spec.hashbytes_len.into();
-        while !self.input.as_ref().is_empty() {
+        'outer: while !self.input.as_ref().is_empty() {
             if !self.spec.path_to_store.is_empty() {
                 let p2sas = self.spec.path_to_store;
-                if self.input.as_ref().starts_with(p2sas.as_bytes()) {
-                    self.input.split_to(p2sas.len());
-                } else {
+                while !self.input.as_ref().starts_with(p2sas.as_bytes()) {
+                    if self.input.as_ref().is_empty() {
+                        break 'outer;
+                    }
                     self.input.split_to(1);
-                    continue;
+                }
+                self.input.split_to(p2sas.len());
+                if self.input.as_ref().is_empty() {
+                    break 'outer;
                 }
             }
             let hsep = matches!(self.input.as_ref().iter().next(), Some(b'/') | Some(b'\\'));
-            if self.input.as_ref().is_empty() {
-                break;
-            }
             self.input.split_to(1);
             if hsep && self.spec.check_rest(self.input.as_ref()) {
                 // we have found a valid hash