]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Tiny optimization.
authorBruno Haible <bruno@clisp.org>
Mon, 24 May 2010 08:44:42 +0000 (10:44 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 3 Jun 2010 13:03:47 +0000 (15:03 +0200)
gettext-tools/libgrep/ChangeLog
gettext-tools/libgrep/m-fgrep.c

index dd951dbc65b16409e19cd464ba26055b72d471d9..8804b00d7d1b6dbf84b640e719feaf7055092f19 100644 (file)
@@ -1,3 +1,8 @@
+2010-05-24  Bruno Haible  <bruno@clisp.org>
+
+       Tiny optimization.
+       * m-fgrep.c (Fexecute): New local variable buflim.
+
 2010-05-24  Bruno Haible  <bruno@clisp.org>
 
        * m-fgrep.c (Fcompile, Fexecute): Reduce scope of local variables.
index 5c92365b3b941f20ed9edfba2d8611c6d5219cbd..7bb3715eb2d63949a2e49eebdd68e0fc324647c4 100644 (file)
@@ -157,6 +157,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
 {
   struct compiled_kwset *ckwset = (struct compiled_kwset *) compiled_pattern;
   char eol = ckwset->eolbyte;
+  register const char *buflim = buf + buf_size;
   register const char *beg;
   register size_t len;
 #ifdef MBS_SUPPORT
@@ -165,11 +166,10 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
     mb_properties = check_multibyte_string (buf, buf_size);
 #endif /* MBS_SUPPORT */
 
-  for (beg = buf; beg <= buf + buf_size; ++beg)
+  for (beg = buf; beg <= buflim; ++beg)
     {
       struct kwsmatch kwsmatch;
-      size_t offset =
-        kwsexec (ckwset->kwset, beg, buf + buf_size - beg, &kwsmatch);
+      size_t offset = kwsexec (ckwset->kwset, beg, buflim - beg, &kwsmatch);
       if (offset == (size_t) -1)
         {
 #ifdef MBS_SUPPORT
@@ -197,7 +197,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
         {
           if (beg > buf && beg[-1] != eol)
             continue;
-          if (beg + len < buf + buf_size && beg[len] != eol)
+          if (beg + len < buflim && beg[len] != eol)
             continue;
           goto success;
         }
@@ -208,7 +208,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
             {
               if (curr > buf && IS_WORD_CONSTITUENT ((unsigned char) curr[-1]))
                 break;
-              if (curr + len < buf + buf_size
+              if (curr + len < buflim
                   && IS_WORD_CONSTITUENT ((unsigned char) curr[len]))
                 {
                   offset = kwsexec (ckwset->kwset, beg, --len, &kwsmatch);
@@ -241,11 +241,11 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
   {
     register const char *end;
 
-    end = (const char *) memchr (beg + len, eol, (buf + buf_size) - (beg + len));
+    end = (const char *) memchr (beg + len, eol, buflim - (beg + len));
     if (end != NULL)
       end++;
     else
-      end = buf + buf_size;
+      end = buflim;
     while (buf < beg && beg[-1] != eol)
       --beg;
     *match_size = end - beg;