texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[7711] match_in_match_list combine code


From: gavinsmith0123
Subject: [7711] match_in_match_list combine code
Date: Sun, 9 Apr 2017 11:14:15 -0400 (EDT)

Revision: 7711
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7711
Author:   gavin
Date:     2017-04-09 11:14:14 -0400 (Sun, 09 Apr 2017)
Log Message:
-----------
match_in_match_list combine code

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2017-04-09 09:37:33 UTC (rev 7710)
+++ trunk/ChangeLog     2017-04-09 15:14:14 UTC (rev 7711)
@@ -1,5 +1,11 @@
 2017-04-09  Gavin Smith  <address@hidden>
 
+       * info/search.c (match_in_match_list): Combine code for 
+       searching backwards and forwards, and do not get all the matches 
+       in the node if searching backwards.
+
+2017-04-09  Gavin Smith  <address@hidden>
+
        * info/t/file-index-colons.sh: New test of reading an index 
        entry with a colon.
 

Modified: trunk/info/search.c
===================================================================
--- trunk/info/search.c 2017-04-09 09:37:33 UTC (rev 7710)
+++ trunk/info/search.c 2017-04-09 15:14:14 UTC (rev 7711)
@@ -415,7 +415,7 @@
 /* **************************************************************** */
 /* Search forwards or backwards for entries in MATCHES that start within
    the search area.  The search is forwards if START_IN is greater than
-   END_IN.  Return offset of match in *MATCH_INDEX. */
+   END_IN.  Return index of match in *MATCH_INDEX. */
 enum search_result
 match_in_match_list (MATCH_STATE *match_state,
                      long start_in, long end_in, int *match_index)
@@ -422,6 +422,9 @@
 {
   regmatch_t *matches = match_state->matches;
   size_t match_count = match_state->match_count;
+  int searching_backwards = 0;
+  int i;
+  int index = -1;
 
   regoff_t start, end;
   if (start_in < end_in)
@@ -438,57 +441,41 @@
     }
   
   if (start_in > end_in)
+    searching_backwards = 1;
+
+  for (i = 0; i < match_count || !match_state->finished; i++)
     {
-      /* searching backward */
-      int i;
-
-      /* get all matches */
-      while (!match_state->finished)
-        extend_matches (match_state);
-
-      matches = match_state->matches;
-      match_count = match_state->match_count;
-
-      for (i = match_count - 1; i >= 0; i--)
+      /* get more matches as we need them */
+      if (i == match_count)
         {
-          if (matches[i].rm_so < start)
-            break; /* No matches found in search area. */
+          extend_matches (match_state);
+          matches = match_state->matches;
+          match_count = match_state->match_count;
 
-          if (matches[i].rm_so < end)
-           {
-              *match_index = i;
-             return search_success;
-           }
+          if (i == match_count)
+            break;
         }
-    }
-  else
-    {
-      /* searching forward */
-      int i;
-      for (i = 0; i < match_count || !match_state->finished; i++)
-        {
-          /* get more matches as we need them */
-          if (i == match_count)
-            {
-              extend_matches (match_state);
-              matches = match_state->matches;
-              match_count = match_state->match_count;
 
-              if (i == match_count)
-                break;
-            }
+      if (matches[i].rm_so >= end)
+        break; /* No matches found in search area. */
 
-          if (matches[i].rm_so >= end)
-            break; /* No matches found in search area. */
-
-          if (matches[i].rm_so >= start)
+      if (matches[i].rm_so >= start)
+        {
+          index = i;
+          if (!searching_backwards)
             {
-              *match_index = i;
-             return search_success;
+              *match_index = index;
+              return search_success;
             }
         }
     }
 
+  if (index != -1)
+    {
+      *match_index = index;
+      return search_success;
+    }
+
   /* not found */
   return search_not_found;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]