From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#35708: [27.0.50]: thingatpt.el, thing-at-point-looking-at redundant Date: Wed, 15 May 2019 08:59:19 +0200 Message-ID: <6bf2ad95-5a41-cbf1-c5ea-07dc06d0f9a1@easy-emacs.de> References: <8a73a0c9-5b38-4089-2780-28e62a1e162b@easy-emacs.de> <87ftpih6hs.fsf@gmail.com> <1bbebe25-9c4e-2563-701b-9bed85fcabb0@easy-emacs.de> <8536lixikt.fsf@gmail.com> <364b372e-7896-d92c-f848-0e7abc152a20@easy-emacs.de> <2d6578ec-8d7c-d3d0-7d1c-08eab22cae79@easy-emacs.de> <85tvdxw1dc.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="259706"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux i686; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 Cc: 35708@debbugs.gnu.org To: npostavs@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 15 09:00:16 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQntf-0015Qy-Mi for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 09:00:15 +0200 Original-Received: from localhost ([127.0.0.1]:60672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQnte-0006fO-KX for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 03:00:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:52558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQntX-0006eq-KW for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 03:00:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQntW-0004uI-93 for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 03:00:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37282) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQntS-0004l1-Tv for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 03:00:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQntS-0007lS-PN for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 03:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 May 2019 07:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35708 X-GNU-PR-Package: emacs Original-Received: via spool by 35708-submit@debbugs.gnu.org id=B35708.155790356929774 (code B ref 35708); Wed, 15 May 2019 07:00:02 +0000 Original-Received: (at 35708) by debbugs.gnu.org; 15 May 2019 06:59:29 +0000 Original-Received: from localhost ([127.0.0.1]:50826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQnsu-0007k9-UE for submit@debbugs.gnu.org; Wed, 15 May 2019 02:59:29 -0400 Original-Received: from mout.kundenserver.de ([217.72.192.73]:54847) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQnst-0007jx-Dq for 35708@debbugs.gnu.org; Wed, 15 May 2019 02:59:27 -0400 Original-Received: from [192.168.178.31] ([88.130.49.114]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MploR-1guRDZ1tWf-00qDvx; Wed, 15 May 2019 08:59:20 +0200 In-Reply-To: <85tvdxw1dc.fsf@gmail.com> Content-Language: en-US X-Provags-ID: V03:K1:N0DtEay4rmAUGQoejyAf9o5C+KMm6sxa0OMBQl5rzkveIR8SznN mM8if+z6lqGyFQwOMro9bE5G4UcgpSiDPeaFlFQa8Fb4eqDZkNTnK7ckZ/TSbIlp/ko2OGV a6CKSjc5cdhDnuLBVgqIkNdR7ln9Bkn1fN0YPeUaiAyJbQol56oj7DRSC02tQMlAGLMavXa iPuWePX6VkIh4x20ejh2w== X-UI-Out-Filterresults: notjunk:1;V03:K0:UAnWTBdQDww=:b669cvt9Ilm08smr5qjaoM 4AcFaMlh1C/aQh5twI9MuWUuYXrX7FvY7vytBFPtrg3O8L3CogLFpq32fXSyCUKYPryDOkNGz CH6t4uk3vaJ959zsbdbaMibt7fgVVbzc4bp0g50Vs333CdLDLaTH3PIqpChNT203w9Y66MdqC BdUDiSF+VHrGXyY6FKsPlTSUbtLktS3oFcHLlHx4qBUVuIX2gzrPHuEQhCtiCgV0INlo0uFKw 6Nauaz2TTBPNXtXx+WM+8ZkYEwOPm+WH42OGVjxABc3evnPKjxLo9RpUkCOMF7XMirN+m1ZcM mcq7e0uiu687ANLa65ihTtR9bPX6dSErev7Dh2OW4lFeld9cdF1wsb5rpCWpJ0eJucEUYuLiW TdwGgNmlVanTk+5l9WJN8Khut083G3aWXeJrbzo2v9+kXtUQFy+yWohRwcw+XmJilYq+wgX2q TAWAlUsYn4XbZEHGE2kGcQzosDfg0uvzBcbT6eBNDZmwCak17lZZxZYqaZrf8+UF9lEog4dhc NJtKQ5BRRCYGxRz1rHPBuzY+Gpv/5B1HtJFxmC9Ifb1w0xjMSE7Jp5QwYJDKROocllc8kA0Xr 1JoFcJLWnYbUJFsAVKQ7DW7yQ7vjiH2dbS3rKqyNw1UccWXTJaeMnITputLK5dTrF9cU1CGe6 ulsRN+35s9znf03dWS8fGCGCEHgeWYs6oga05SRrZnIvczzClmtiRoD/dlN3Uepn3Trkwkx65 FS4McMTCa8JvOrxDEu1HmgCqZxNuVuSavCYtbx9hYCAJzKTFynuFQiYf9L3Rrvk0FbUa/MjB X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159324 Archived-At: Am 14.05.19 um 16:34 schrieb npostavs@gmail.com: > Andreas Röhler writes: > >>> Hmm, current thing-at-point-looking-at might be slow with large >>> buffers. The slightly modified test should reveal it: >>> >>> (ert-deftest thing-at-point-looking-at-2 () >>>   (with-temp-buffer >>>     (insert "1abcd 222abcd") >>>     (dotimes (_ 99999) (insert " asdf ")) >>>     (goto-char (point-min)) >>>       (search-forward "2ab") >>>       (should (thing-at-point-looking-at "2abcd")) > Yes, in this case, since the loop over looking-at only needs to iterate > twice, so it will be faster. But what about when there is no match? > E.g., > > (with-temp-buffer > (dotimes (_ 99999) (insert " asdf ")) > (goto-char (point-max)) > (list :ar-regexp-atpt (benchmark-run (ar-regexp-atpt "foo")) > :thing-at-point-looking-at (benchmark-run (thing-at-point-looking-at "foo")))) > >> Another fix, as a bug showed up when testing (ar-regexp-atpt "[a-z]+"): >> >> (defun ar-regexp-atpt (regexp) >>   "Return t if REGEXP matches at or before point, nil otherwise. >> >> Changes match-data" >>   (save-excursion >>     (if (looking-at regexp) >>     (while >>         (and (not (bobp)) >>          (or (progn (backward-char) (looking-at regexp)) >>              (forward-char 1)))) >>       (while (not (or (bobp) (backward-char) (looking-at regexp)))) >>       (ar-regexp-atpt regexp)) > What's this recursive call for? It triggers (error "Lisp nesting > exceeds ‘max-lisp-eval-depth’") in the benchmark above. > >>     (looking-at regexp))) The recursive call needed a guard:     (unless (bobp) It is called after function went backward while not looking-at matches, Now the result for the 99999 is (:ar-regexp-atpt (0.774574453 0 0.0) :thing-at-point-looking-at (0.000798669 0 0.0)) The fixed form: (defun ar-regexp-atpt (regexp)   "Return t if REGEXP matches at or before point, nil otherwise. Changes match-data"   (save-excursion     (if (looking-at regexp)     (while         (and (not (bobp))          (or (progn (backward-char) (looking-at regexp))              (forward-char 1))))       (while (not (or (bobp) (backward-char) (looking-at regexp))))       (unless (bobp) (ar-regexp-atpt regexp)))     (looking-at regexp)))