]> git.eshelyaron.com Git - emacs.git/commitdiff
(Ftry_completion, Fall_completions): Do lazy binding
authorDavid Kastrup <dak@gnu.org>
Sun, 20 Jun 2004 22:29:47 +0000 (22:29 +0000)
committerDavid Kastrup <dak@gnu.org>
Sun, 20 Jun 2004 22:29:47 +0000 (22:29 +0000)
and unbinding of `case-fold-search' according to
`completion-ignore-case' around calls of string-match and
predicates, respectively.  Should give satisfactory performance
in all relevant cases.

src/ChangeLog
src/minibuf.c

index 2c1db9730f04828c1eb4f3f2a2336f0aff0a962a..f30631f83ef8f3730ff66f5b2e210b698c6c290a 100644 (file)
@@ -1,3 +1,11 @@
+2004-06-21  David Kastrup  <dak@gnu.org>
+
+       * minibuf.c (Ftry_completion, Fall_completions): Do lazy binding
+       and unbinding of `case-fold-search' according to
+       `completion-ignore-case' around calls of string-match and
+       predicates, respectively.  Should give satisfactory performance
+       in all relevant cases.
+
 2004-06-17  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
 
        * xterm.c (x_draw_image_foreground_1): Subtract slice.x/y from
index ee37142a4a673d707b6a030135c767eb7b806a94..dd7bb42263b9b94f8f06f4b9519fd13bd79970e2 100644 (file)
@@ -1207,6 +1207,7 @@ is used to further constrain the set of candidates.  */)
                           || NILP (XCAR (alist))));
   int index = 0, obsize = 0;
   int matchcount = 0;
+  int bindcount = -1;
   Lisp_Object bucket, zero, end, tem;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1285,21 +1286,22 @@ is used to further constrain the set of candidates.  */)
          XSETFASTINT (zero, 0);
 
          /* Ignore this element if it fails to match all the regexps.  */
-         if (CONSP (Vcompletion_regexp_list))
-           {
-             int count = SPECPDL_INDEX ();
-             specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
-             for (regexps = Vcompletion_regexp_list; CONSP (regexps);
-                  regexps = XCDR (regexps))
-               {
-                 tem = Fstring_match (XCAR (regexps), eltstring, zero);
-                 if (NILP (tem))
-                   break;
+         {
+           for (regexps = Vcompletion_regexp_list; CONSP (regexps);
+                regexps = XCDR (regexps))
+             {
+               if (bindcount < 0) {
+                 bindcount = SPECPDL_INDEX ();
+                 specbind (Qcase_fold_search,
+                           completion_ignore_case ? Qt : Qnil);
                }
-             unbind_to (count, Qnil);
-             if (CONSP (regexps))
-               continue;
-           }
+               tem = Fstring_match (XCAR (regexps), eltstring, zero);
+               if (NILP (tem))
+                 break;
+             }
+           if (CONSP (regexps))
+             continue;
+         }
 
          /* Ignore this element if there is a predicate
             and the predicate doesn't like it. */
@@ -1310,6 +1312,10 @@ is used to further constrain the set of candidates.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
+                 if (bindcount >= 0) {
+                   unbind_to (bindcount, Qnil);
+                   bindcount = -1;
+                 }
                  GCPRO4 (tail, string, eltstring, bestmatch);
                  tem = type == 3
                    ? call2 (predicate, elt,
@@ -1391,6 +1397,11 @@ is used to further constrain the set of candidates.  */)
        }
     }
 
+  if (bindcount >= 0) {
+    unbind_to (bindcount, Qnil);
+    bindcount = -1;
+  }
+
   if (NILP (bestmatch))
     return Qnil;               /* No completions found */
   /* If we are ignoring case, and there is no exact match,
@@ -1453,6 +1464,7 @@ are ignored unless STRING itself starts with a space.  */)
                       && (!SYMBOLP (XCAR (alist))
                           || NILP (XCAR (alist))));
   int index = 0, obsize = 0;
+  int bindcount = -1;
   Lisp_Object bucket, tem;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1537,21 +1549,22 @@ are ignored unless STRING itself starts with a space.  */)
          XSETFASTINT (zero, 0);
 
          /* Ignore this element if it fails to match all the regexps.  */
-         if (CONSP (Vcompletion_regexp_list))
-           {
-             int count = SPECPDL_INDEX ();
-             specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
-             for (regexps = Vcompletion_regexp_list; CONSP (regexps);
-                  regexps = XCDR (regexps))
-               {
-                 tem = Fstring_match (XCAR (regexps), eltstring, zero);
-                 if (NILP (tem))
-                   break;
+         {
+           for (regexps = Vcompletion_regexp_list; CONSP (regexps);
+                regexps = XCDR (regexps))
+             {
+               if (bindcount < 0) {
+                 bindcount = SPECPDL_INDEX ();
+                 specbind (Qcase_fold_search,
+                           completion_ignore_case ? Qt : Qnil);
                }
-             unbind_to (count, Qnil);
-             if (CONSP (regexps))
-               continue;
-           }
+               tem = Fstring_match (XCAR (regexps), eltstring, zero);
+               if (NILP (tem))
+                 break;
+             }
+           if (CONSP (regexps))
+             continue;
+         }
 
          /* Ignore this element if there is a predicate
             and the predicate doesn't like it. */
@@ -1562,6 +1575,10 @@ are ignored unless STRING itself starts with a space.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
+                 if (bindcount >= 0) {
+                   unbind_to (bindcount, Qnil);
+                   bindcount = -1;
+                 }
                  GCPRO4 (tail, eltstring, allmatches, string);
                  tem = type == 3
                    ? call2 (predicate, elt,
@@ -1576,6 +1593,11 @@ are ignored unless STRING itself starts with a space.  */)
        }
     }
 
+  if (bindcount >= 0) {
+    unbind_to (bindcount, Qnil);
+    bindcount = -1;
+  }
+
   return Fnreverse (allmatches);
 }
 \f