From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: [harder@ifa.au.dk: Speed of all-completions] Date: 15 Jun 2004 15:27:53 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1087306104 10075 80.91.224.253 (15 Jun 2004 13:28:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 15 Jun 2004 13:28:24 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Jun 15 15:28:15 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BaDz4-0000HX-00 for ; Tue, 15 Jun 2004 15:28:14 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BaDz4-0000bN-00 for ; Tue, 15 Jun 2004 15:28:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BaE00-0000vx-Mr for emacs-devel@quimby.gnus.org; Tue, 15 Jun 2004 09:29:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BaDzr-0000vr-JJ for emacs-devel@gnu.org; Tue, 15 Jun 2004 09:29:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BaDzr-0000vf-3T for emacs-devel@gnu.org; Tue, 15 Jun 2004 09:29:03 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BaDzr-0000vc-19 for emacs-devel@gnu.org; Tue, 15 Jun 2004 09:29:03 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BaDys-0003dE-80 for emacs-devel@gnu.org; Tue, 15 Jun 2004 09:28:02 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1BaDyk-0007ZC-UI; Tue, 15 Jun 2004 09:27:55 -0400 Original-To: Andreas Schwab In-Reply-To: Original-Lines: 45 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24989 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24989 --=-=-= Andreas Schwab writes: > David Kastrup writes: > > > Andreas Schwab writes: > > > >> David Kastrup writes: > >> > >> > Andreas Schwab writes: > >> > > >> >> This is due to this change: > >> >> > >> >> (Ftry_completion, Fall_completions, Ftest_completion): Bind > >> >> case-fold-search to the value of completion-ignore-case when > >> >> checking completion-regexp-list. > >> >> > >> >> I've checked in a fix that avoids the overhead of specbind when > >> >> completion-regexp-list is empty. > >> > > >> > At the cost of being more expensive when it isn't. > >> > >> Why is it more expensive? The check for CONSP (completion-regexp-list) > >> has to be done anyway, and can be CSE'd by the compiler. > > > > Because you are redoing the binding for every element in the loop, > > while it is needed only once. > > I did not change anything in this regard. Serves me right from just looking at the result instead of what you started with. To illustrate what I mean, here is a patch against the most recent version. Note that I have to undo the binding before calling a user-defined predicate function (which might rely on the original binding). The last of your three changes, not running in a loop, was not improvable, however. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment --- minibuf.c 15 Jun 2004 00:47:07 +0200 1.269 +++ minibuf.c 15 Jun 2004 15:22:48 +0200 @@ -1207,6 +1207,7 @@ || NILP (XCAR (alist)))); int index = 0, obsize = 0; int matchcount = 0; + int bind_count = -1; Lisp_Object bucket, zero, end, tem; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; @@ -1285,21 +1286,22 @@ 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 (bind_count < 0) { + bind_count = 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 @@ tem = Fcommandp (elt, Qnil); else { + if (bind_count >= 0) { + unbind_to (bind_count, Qnil); + bind_count = -1; + } GCPRO4 (tail, string, eltstring, bestmatch); tem = type == 3 ? call2 (predicate, elt, @@ -1391,6 +1397,11 @@ } } + if (bind_count >= 0) { + unbind_to (bind_count, Qnil); + bind_count = -1; + } + if (NILP (bestmatch)) return Qnil; /* No completions found */ /* If we are ignoring case, and there is no exact match, @@ -1453,6 +1464,7 @@ && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist)))); int index = 0, obsize = 0; + int bind_count = -1; Lisp_Object bucket, tem; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; @@ -1537,21 +1549,22 @@ 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 (bind_count < 0) { + bind_count = 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 @@ tem = Fcommandp (elt, Qnil); else { + if (bind_count >= 0) { + unbind_to (bind_count, Qnil); + bind_count = -1; + } GCPRO4 (tail, eltstring, allmatches, string); tem = type == 3 ? call2 (predicate, elt, @@ -1576,6 +1593,11 @@ } } + if (bind_count >= 0) { + unbind_to (bind_count, Qnil); + bind_count = -1; + } + return Fnreverse (allmatches); } --=-=-= Does this look sane enough? -- David Kastrup, Kriemhildstr. 15, 44793 Bochum --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--