From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#67536: 29.1; Calc mode's math-read-preprocess-string conses unnecessarily Date: Sat, 2 Dec 2023 15:56:54 +0100 Message-ID: References: <83h6l367zx.fsf@gnu.org> <83jzpzaw9s.fsf@gnu.org> <834jh1aj1d.fsf@gnu.org> <83lead81zq.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_BB5A896F-CC0D-4C80-BF01-B61DBAA77C7D" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1974"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67536@debbugs.gnu.org, Stefan Monnier , Raffael Stocker To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 02 15:58:07 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 1r9RRW-0000Gx-7c for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Dec 2023 15:58:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9RRK-0005nr-Fx; Sat, 02 Dec 2023 09:57:54 -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 1r9RRI-0005nd-Jh for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 09:57:53 -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 1r9RRI-0004NY-Bb for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 09:57:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9RRR-000445-M9 for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 09:58:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Dec 2023 14:58:01 +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.170152903415574 (code B ref 67536); Sat, 02 Dec 2023 14:58:01 +0000 Original-Received: (at 67536) by debbugs.gnu.org; 2 Dec 2023 14:57:14 +0000 Original-Received: from localhost ([127.0.0.1]:58399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9RQg-000437-58 for submit@debbugs.gnu.org; Sat, 02 Dec 2023 09:57:14 -0500 Original-Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]:57842) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9RQe-00042w-9I for 67536@debbugs.gnu.org; Sat, 02 Dec 2023 09:57:12 -0500 Original-Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-50bc8a9503fso4244051e87.3 for <67536@debbugs.gnu.org>; Sat, 02 Dec 2023 06:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701529017; x=1702133817; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=f7yXxCjep27h03xgXglg3fkEdb5ca36KxgX2FR6/wkI=; b=U86yU09bAXsYWldoGJ0wbhxTmd6KZYMWxipVRhsk1Y4541JKLU0QSpQC4ZVTdeUxlq jt3HzpqRZICQ5VuUAITweNGGBljNtBaXrnIaxoBwXffh7rxJiX/qyn5bDChmqNxUvCIQ m+ex6el9lGRtRmqlwRfcmehuBUPvJh3lswAoiKLJwnoaP6dwGJGBGUEhFmzqdTHlskJI 3ONX/v4MkszV1MHa90U4Rl0QkAFQCQh3XRCtil4ABJ3SSH+jFN8pBRGEKQKtZgYpaS3E JUrMXjQyklVgAeMJQLdJJJc7Fd5fEJJadfmgj63J8FYGheBCe1sSwrMhueMx1Fp/CYZr TTxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701529017; x=1702133817; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f7yXxCjep27h03xgXglg3fkEdb5ca36KxgX2FR6/wkI=; b=EttVHSLe1byMN093SzNbMLgWNhxiUqpKcNxsTaWJWyeBVfoerbDX8a+FHZjnu1DJ2i XEkFOBPc0/A4pyMRt8s6FV4tvSmK7ffbwsP0ySMXHjcaS0a7Ef1g/fKWgCmN0R7ifzG0 xCAIYVwUbefRjapF+el93vN2LACvtr5jxs2YHRexBznpnCicpjmvau1gRVlPIPRF4JQF MOK6/lVLOQCPBTWu4tnpXTQGGGlPs7fjqVVNtQ6AeLVICPy4YJOYrEqOfQQ6/GXnpF4i bu8oMiA90fFG5dmFRH/Eom638f4yC8XtAPCymBNQI5osZQu0zOaBvN2LpzwYqvno90CJ D8IA== X-Gm-Message-State: AOJu0YxaU8grO2lnGJb/eYSIQ5ifpnycqcyOJ74CjY3p0Bxe7ZwDlmtr TY/hh1yTk3z5EC6mYHBsPJI= X-Google-Smtp-Source: AGHT+IFpU1YBDuSZ5LJPYmfkTBnAGZX7iJ9dccfJfw4PhG4Wjs+/gg0fitJsp26CqKED5fMc6iH7iQ== X-Received: by 2002:a19:2d1b:0:b0:50b:d764:87fb with SMTP id k27-20020a192d1b000000b0050bd76487fbmr1629509lfj.71.1701529016471; Sat, 02 Dec 2023 06:56:56 -0800 (PST) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id q25-20020a056512211900b004fb7359ab83sm244667lfr.80.2023.12.02.06.56.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Dec 2023 06:56:56 -0800 (PST) In-Reply-To: <83lead81zq.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.15) 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:275387 Archived-At: --Apple-Mail=_BB5A896F-CC0D-4C80-BF01-B61DBAA77C7D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 2 dec. 2023 kl. 09.03 skrev Eli Zaretskii : > Mattias, any comments, or should I install this? Well, the patch doesn't look too unreasonable so installing it would = leave us better off than before. Of course we may want to try to do better if this is really a = bottleneck. The big job was to detect and locate the inefficiency -- = thank you, Raffael! -- so his efforts were instrumental in any case. There are minor points that could be addressed: `mapc` is often better = replaced with `dolist`; the first position of a buffer is 1, not 0; and = perhaps iterating through all elements of math-read-replacement-list = isn't ideal. Here's a variant which computes a single regexp to do the job and should = cons a bit less. Raffael, maybe you could see if this makes a difference in Org table = performance. --Apple-Mail=_BB5A896F-CC0D-4C80-BF01-B61DBAA77C7D Content-Disposition: attachment; filename=math-read-preprocess-string.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="math-read-preprocess-string.diff" Content-Transfer-Encoding: quoted-printable diff=20--git=20a/lisp/calc/calc-aent.el=20b/lisp/calc/calc-aent.el=0A= index=2066ede3295ae..4c1c464512a=20100644=0A---=20= a/lisp/calc/calc-aent.el=0A+++=20b/lisp/calc/calc-aent.el=0A@@=20-547,22=20= +547,36=20@@=20math-read-subscripts=0A=20=20=20= "=E2=82=80=E2=82=81=E2=82=82=E2=82=83=E2=82=84=E2=82=85=E2=82=86=E2=82=87=E2= =82=88=E2=82=89=E2=82=8A=E2=82=8B=E2=82=8D=E2=82=8E"=20;=20= 0123456789+-()=0A=20=20=20"A=20string=20consisting=20of=20the=20= subscripts=20allowed=20by=20Calc.")=0A=20=0A+(defvar=20= math--read-preprocess-re-cache=20nil=0A+=20=20"Cached=20regexp=20and=20= tag:=20(REGEXP=20REPLACEMENTS=20SUPERSCRIPTS=20SUBSCRIPTS)")=0A+=0A=20= ;;;###autoload=0A=20(defun=20math-read-preprocess-string=20(str)=0A=20=20= =20"Replace=20some=20substrings=20of=20STR=20by=20Calc=20equivalents."=0A= -=20=20(setq=20str=0A-=20=20=20=20=20=20=20=20(replace-regexp-in-string=20= (concat=20"["=20math-read-superscripts=20"]+")=0A-=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20"^(\\&)"=20str))=0A-=20=20(setq=20str=0A-=20=20=20=20=20=20=20=20= (replace-regexp-in-string=20(concat=20"["=20math-read-subscripts=20"]+")=0A= -=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20"_(\\&)"=20str))=0A-=20=20(let=20= ((rep-list=20math-read-replacement-list))=0A-=20=20=20=20(while=20= rep-list=0A-=20=20=20=20=20=20(setq=20str=0A-=20=20=20=20=20=20=20=20=20=20= =20=20(replace-regexp-in-string=20(nth=200=20(car=20rep-list))=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(nth=201=20(car=20rep-list))=20str))=0A-=20= =20=20=20=20=20(setq=20rep-list=20(cdr=20rep-list))))=0A-=20=20str)=0A+=20= =20(unless=20(and=20(eq=20(nth=201=20math--read-preprocess-re-cache)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= math-read-replacement-list)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(eq=20(nth=202=20math--read-preprocess-re-cache)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20math-read-superscripts)=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(eq=20(nth=203=20= math--read-preprocess-re-cache)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20math-read-subscripts))=0A+=20=20=20=20;;=20Cache=20= invalid,=20recompute.=0A+=20=20=20=20(setq=20= math--read-preprocess-re-cache=0A+=20=20=20=20=20=20=20=20=20=20(list=20= (rx-to-string=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20`(or=20= (group=20(in=20,math-read-superscripts))=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(group=20(in=20= ,math-read-subscripts))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(group=20(or=20,@(mapcar=20#'car=20= math-read-replacement-list))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20t)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= math-read-replacement-list=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20math-read-superscripts=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20math-read-subscripts)))=0A+=20=20(replace-regexp-in-string=0A+=20=20=20= (nth=200=20math--read-preprocess-re-cache)=0A+=20=20=20(lambda=20(s)=0A+=20= =20=20=20=20(let=20((r=20(cadr=20(assoc=20s=20= math-read-replacement-list))))=0A+=20=20=20=20=20=20=20(cond=20= ((match-beginning=201)=20(concat=20"^("=20r=20")"))=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20((match-beginning=202)=20(concat=20"_("=20r=20")"))=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20(t=20r))))=0A+=20=20=20str=20t))=0A= =20=0A=20;;=20The=20next=20few=20variables=20are=20local=20to=20= math-read-exprs=20(and=20math-read-expr=0A=20;;=20in=20calc-ext.el),=20= but=20are=20set=20in=20functions=20they=20call.=0A= --Apple-Mail=_BB5A896F-CC0D-4C80-BF01-B61DBAA77C7D--