From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#29866: 27.0.50; cl-loop: Calculate the array length just once Date: Thu, 28 Dec 2017 05:13:21 +0900 Message-ID: <87y3lo9bfi.fsf@gmail.com> References: <87wp18179m.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1514405537 11373 195.159.176.226 (27 Dec 2017 20:12:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 27 Dec 2017 20:12:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: monnier@iro.umontreal.ca To: 29866@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 27 21:12:12 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUI3f-0002ZG-Fc for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 21:12:11 +0100 Original-Received: from localhost ([::1]:46199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUI5d-0002RZ-W0 for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 15:14:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUI5W-0002R5-97 for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 15:14:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUI5S-0004U9-W7 for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 15:14:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUI5S-0004T4-LK for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 15:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eUI5S-0000dk-DD for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 15:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Dec 2017 20:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29866 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 29866-submit@debbugs.gnu.org id=B29866.15144056182419 (code B ref 29866); Wed, 27 Dec 2017 20:14:02 +0000 Original-Received: (at 29866) by debbugs.gnu.org; 27 Dec 2017 20:13:38 +0000 Original-Received: from localhost ([127.0.0.1]:54186 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUI53-0000cv-Dy for submit@debbugs.gnu.org; Wed, 27 Dec 2017 15:13:38 -0500 Original-Received: from mail-wr0-f194.google.com ([209.85.128.194]:39396) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUI4z-0000cf-W4 for 29866@debbugs.gnu.org; Wed, 27 Dec 2017 15:13:34 -0500 Original-Received: by mail-wr0-f194.google.com with SMTP id o101so8961032wrb.6 for <29866@debbugs.gnu.org>; Wed, 27 Dec 2017 12:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=j2wGRug+zDaWc3VqIHyGe2tCobUSX38mb05uh0Ic3OA=; b=h/LYhkRB3z6uHUY8bmWVNp0fHO+m+u5yJ6nO1a+jIxjEEeMAikliVA+SGefxU0Z0FK KkP0c50le2P1EThFK3QbCX6z6243yr8m50AGKo3yBWDVJfoBSWtpMrO3FZ7talaGqFmS 4ineS6tWa+0SQxuN9J4O6QkE0OaG1lcvMbyCwc9kCPpkGVL0X0JvFGl3hStwFClT1JIg prGF5iiZmlAEjY3uEqTNbB383Q1xo0YocHI8cKKo+hxr2RjGqiHJixKsYw1cFby5BODw xijBI0g8escNIt32BoCz8cT53hnt/B/iKaOb+oB0ml9zq5yp1mj1ITMhmERxP8QDB02M ZsKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=j2wGRug+zDaWc3VqIHyGe2tCobUSX38mb05uh0Ic3OA=; b=N38Lc2A1KhoqSh2M9TC4Od6MYoysOjzPSLzft6XROK1UBm/mB4GZzGivUjfaB+ohgH MZqE26Ug5WSDP76GkwmiaJNwNU771fcVLQYpVM4mNCOQ1eluuteYTk2rkPYgaQDiT9P6 BlOPwLXEmqAUDK1246ZUc6tP4sWSm1TvZoLUfvnnCTeFnEAPnGZ4wiF9gZhaOWvwsuOP BdVEYlfEZ3sjDdhlAtnsy0CFqBb4tU4rT+6QXz/0BF6NZSqNCZ36fbIVBsXZ4Td5jGGL tQYP+xQ9As8cjJD7ykaKofKw4oRantrG6UAUe59ACkccXIhcZh1hIJVpA6SsNQU9YKOT 27UQ== X-Gm-Message-State: AKGB3mJjeCyag7nil36oW6jP9DOJzwE0ffDemASJ/qKLq71L4vJ1xCSe 1uHgsP+zsYCN5DFyP1Xh6Ro= X-Google-Smtp-Source: ACJfBot1+Sv+tb8j6PIpgvH71xgynPLaKHguNhvNn2FwFaMjPohgVPUA2C6HcSVNSs6uijlsQTFwOA== X-Received: by 10.223.141.226 with SMTP id o89mr29277492wrb.95.1514405608140; Wed, 27 Dec 2017 12:13:28 -0800 (PST) Original-Received: from calancha-pc (228.red-83-40-68.dynamicip.rima-tde.net. [83.40.68.228]) by smtp.gmail.com with ESMTPSA id i203sm7175682wmf.34.2017.12.27.12.13.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Dec 2017 12:13:27 -0800 (PST) In-Reply-To: <87wp18179m.fsf@gmail.com> (Tino Calancha's message of "Thu, 28 Dec 2017 01:10:29 +0900") 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: 208.118.235.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:141541 Archived-At: Tino Calancha writes: > X-Debbugs-CC: monnier@iro.umontreal.ca > > It looks sensible to calculate the array length just once, > instead of recalculate it on each iteration: I have checked after my nap for more optimizations like that. The patch below pass the tests. As long as the length of the seq be an invariant (is it?), then it must be OK to store it in `temp-seq'. --8<-----------------------------cut here---------------start------------->8--- diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index f671aea399..d70cf7d664 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -1338,6 +1338,7 @@ cl--parse-loop-clause (error "Expected `of'")))) (seq (cl--pop2 cl--loop-args)) (temp-seq (make-symbol "--cl-seq--")) + (temp-len (make-symbol "--cl-len--")) (temp-idx (if (eq (car cl--loop-args) 'using) (if (and (= (length (cadr cl--loop-args)) 2) @@ -1348,16 +1349,19 @@ cl--parse-loop-clause (push (list temp-seq seq) loop-for-bindings) (push (list temp-idx 0) loop-for-bindings) (if ref - (let ((temp-len (make-symbol "--cl-len--"))) + (progn (push (list temp-len `(length ,temp-seq)) loop-for-bindings) (push (list var `(elt ,temp-seq ,temp-idx)) cl--loop-symbol-macs) (push `(< ,temp-idx ,temp-len) cl--loop-body)) + ;; Evaluate seq length just if needed, that is, when seq is not a cons. + (push (list temp-len (or (consp seq) `(length ,temp-seq))) + loop-for-bindings) (push (list var nil) loop-for-bindings) (push `(and ,temp-seq (or (consp ,temp-seq) - (< ,temp-idx (length ,temp-seq)))) + (< ,temp-idx ,temp-len))) cl--loop-body) (push (list var `(if (consp ,temp-seq) (pop ,temp-seq) --8<-----------------------------cut here---------------end--------------->8---