summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Levert <charles_levert@gna.org>2005-07-04 05:12:17 +0000
committerCharles Levert <charles_levert@gna.org>2005-07-04 05:12:17 +0000
commit83805705f58a153e74dc4d0a2626b20bc0a38b33 (patch)
treeecd46044786ed6dfa23ee480fea6f2e08616d0d8
parent1ad7011513af9acbe96171e2cb8d1b17a7b4b240 (diff)
downloadgrep-83805705f58a153e74dc4d0a2626b20bc0a38b33.tar.gz
* src/kwset.c (kwsprep): Optimize search for mind2 value by
starting from the end of the target[] array.
-rw-r--r--ChangeLog3
-rw-r--r--src/kwset.c10
2 files changed, 10 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b129e80..048c2942 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@
* src/kwset.c (kwsprep): Move three variable declarations to
the single {}-block where they are used.
+ * src/kwset.c (kwsprep): Optimize search for mind2 value by
+ starting from the end of the target[] array.
+
2005-06-22 Charles Levert <charles_levert@gna.org>
* grep/autogen.sh, grep/src/Makefile.am, grep/tests/backref.sh,
diff --git a/src/kwset.c b/src/kwset.c
index 4a515c23..03a25e6a 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -393,6 +393,8 @@ kwsprep (kwset_t kws)
of the hairy commentz-walter algorithm. */
if (kwset->words == 1 && kwset->trans == NULL)
{
+ char c;
+
/* Looking for just one string. Extract it from the trie. */
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
@@ -406,9 +408,11 @@ kwsprep (kwset_t kws)
kwset->mind2 = kwset->mind;
/* Find the minimal delta2 shift that we might make after
a backwards match has failed. */
- for (i = 0; i < kwset->mind - 1; ++i)
- if (kwset->target[i] == kwset->target[kwset->mind - 1])
- kwset->mind2 = kwset->mind - (i + 1);
+ c = kwset->target[kwset->mind - 1];
+ for (i = kwset->mind - 2; i >= 0; --i)
+ if (kwset->target[i] == c)
+ break;
+ kwset->mind2 = kwset->mind - (i + 1);
}
else
{