From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Raffael Stocker Newsgroups: gmane.emacs.bugs Subject: bug#67536: 29.1; Calc mode's math-read-preprocess-string conses unnecessarily Date: Fri, 01 Dec 2023 22:10:22 +0100 Message-ID: References: <83h6l367zx.fsf@gnu.org> <83jzpzaw9s.fsf@gnu.org> <834jh1aj1d.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20378"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.10.8; emacs 29.1 Cc: 67536@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 01 22:16:16 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r9Arw-000585-84 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Dec 2023 22:16:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Are-0006rq-33; Fri, 01 Dec 2023 16:15:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Ara-0006rN-5C for bug-gnu-emacs@gnu.org; Fri, 01 Dec 2023 16:15:54 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9ArZ-0007dN-LR for bug-gnu-emacs@gnu.org; Fri, 01 Dec 2023 16:15:53 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9Ari-00020i-A1 for bug-gnu-emacs@gnu.org; Fri, 01 Dec 2023 16:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Raffael Stocker Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Dec 2023 21:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67536 X-GNU-PR-Package: emacs Original-Received: via spool by 67536-submit@debbugs.gnu.org id=B67536.17014653277686 (code B ref 67536); Fri, 01 Dec 2023 21:16:02 +0000 Original-Received: (at 67536) by debbugs.gnu.org; 1 Dec 2023 21:15:27 +0000 Original-Received: from localhost ([127.0.0.1]:56205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9Ar8-0001zt-I8 for submit@debbugs.gnu.org; Fri, 01 Dec 2023 16:15:26 -0500 Original-Received: from mail-out.m-online.net ([2001:a60:0:28:0:1:25:1]:58699) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9Ar6-0001zj-6J for 67536@debbugs.gnu.org; Fri, 01 Dec 2023 16:15:26 -0500 Original-Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4Shm6n5hfyz1s95D; Fri, 1 Dec 2023 22:15:13 +0100 (CET) Original-Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 4Shm6n3rbkz1qqlS; Fri, 1 Dec 2023 22:15:13 +0100 (CET) X-Virus-Scanned: amavis at mnet-online.de Original-Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavis, port 10024) with ESMTP id 0sEfaQSnbwMT; Fri, 1 Dec 2023 22:15:12 +0100 (CET) X-Auth-Info: TSb3PVXAq9YVbyqVADZRtsZRWJd/j6PglpL/NBl1ctVqUCi+mJrsOJ0FUklgsyLk Original-Received: from Whiteflame (ppp-212-114-182-156.dynamic.mnet-online.de [212.114.182.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 1 Dec 2023 22:15:12 +0100 (CET) In-reply-to: <834jh1aj1d.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275340 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> I use cl-flet and (eval-when-compile (require 'cl-lib)). I hope that is >> ok. > > I'd prefer a simple internal function, or a lambda. I went with the lambda, it is the more concise choice. >> + (buffer-string)))) > > I think buffer-substring-no-properties would be better than > buffer-string, as we don't need to copy any text properties, right? Yes, indeed. I fixed that too. Regards, Raffael --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-calc-calc-aent.el-math-read-preprocess-string-c.patch Content-Description: optimized math-read-preprocess-string >From 68ae1e20ae5eb66cc4899a1e442dae3bb6a054ad Mon Sep 17 00:00:00 2001 From: Raffael Stocker Date: Fri, 1 Dec 2023 22:08:24 +0100 Subject: [PATCH] * lisp/calc/calc-aent.el (math-read-preprocess-string): cons less (bug#67536) Use a temp buffer instead of working on a string. This function is called by calc-eval, which in turn is called repeatedly when re-calculating org-mode tables. This function is one of the main bottlenecks there. --- lisp/calc/calc-aent.el | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el index 66ede3295ae..b79765fbc1f 100644 --- a/lisp/calc/calc-aent.el +++ b/lisp/calc/calc-aent.el @@ -550,19 +550,16 @@ math-read-subscripts ;;;###autoload (defun math-read-preprocess-string (str) "Replace some substrings of STR by Calc equivalents." - (setq str - (replace-regexp-in-string (concat "[" math-read-superscripts "]+") - "^(\\&)" str)) - (setq str - (replace-regexp-in-string (concat "[" math-read-subscripts "]+") - "_(\\&)" str)) - (let ((rep-list math-read-replacement-list)) - (while rep-list - (setq str - (replace-regexp-in-string (nth 0 (car rep-list)) - (nth 1 (car rep-list)) str)) - (setq rep-list (cdr rep-list)))) - str) + (with-temp-buffer + (insert str) + (mapc (lambda (rep-pair) + (goto-char 0) + (while (re-search-forward (car rep-pair) nil t) + (replace-match (cadr rep-pair)))) + `((,(concat "[" math-read-superscripts "]+") "^(\\&)") + (,(concat "[" math-read-subscripts "]+") "_(\\&)") + ,@math-read-replacement-list)) + (buffer-substring-no-properties (point-min) (point-max)))) ;; The next few variables are local to math-read-exprs (and math-read-expr ;; in calc-ext.el), but are set in functions they call. -- 2.43.0 --=-=-=--