Thread (77 messages) 77 messages, 3 authors, 2021-04-12
STALE1920d
Revisions (2)
  1. v1 current
  2. v1 [diff vs current]

[PATCH 14/25] pickaxe -S: remove redundant "sz" check in while-loop

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-02-03 03:30:30
Subsystem: the rest · Maintainer: Linus Torvalds

If we walk to the end of the string we just won't match the rest of
the regex. This removes an optimization for simplicity's sake. In
subsequent commits we'll alter this code more, and not having to think
about this condition makes it easier to read.

If we look at the context of what we're doing here the last thing we
need to be worried about is one extra regex match. The real problem is
that we keep matching after it's clear that the number of contains()
for "A" and "B" is different. So we could be much smarter here.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 diffcore-pickaxe.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 208177bb40..8df76afb6e 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -82,12 +82,11 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
 		regmatch_t regmatch;
 		int flags = 0;
 
-		while (sz &&
-		       !regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
+		while (!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
 			flags |= REG_NOTBOL;
 			data += regmatch.rm_eo;
 			sz -= regmatch.rm_eo;
-			if (sz && regmatch.rm_so == regmatch.rm_eo) {
+			if (regmatch.rm_so == regmatch.rm_eo) {
 				data++;
 				sz--;
 			}
-- 
2.30.0.284.gd98b1dd5eaa7
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help