From 2f431bf8df1a2c4df15c48a94d117d41b0838c6b Mon Sep 17 00:00:00 2001 From: zseri Date: Thu, 30 Dec 2021 02:56:40 +0100 Subject: refactor(zseri/s-r-sc): use inner while loop to improve perf Change-Id: I13e95b91351af33c2452f1c4de45cc47aeae1dc0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4745 Tested-by: BuildkiteCI Reviewed-by: zseri --- users/zseri/store-ref-scanner/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'users') 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 { 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 -- cgit 1.4.1