all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Optimise 'while' bodies for effect
@ 2019-12-26 16:59 Mattias Engdegård
  2019-12-26 18:19 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-12-26 16:59 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Optimising the body of 'while' forms for effect (proposed patch attached) finds the following:

In nnheader-find-nov-line:
~/emacs/lisp/gnus/nnheader.el:449:32:Warning: value returned from (= (setq num
    (read cur)) article) is unused

In ldap-search-internal:
~/emacs/lisp/net/ldap.el:528:30:Warning: value returned from (1+ numres) is
    unused

In org-babel-screen-test:
~/emacs/lisp/org/ob-screen.el:120:4:Warning: value returned from (format
    "org-babel-screen: File not readable yet.") is unused

Not much, perhaps, but worth doing anyway?


[-- Attachment #2: 0001-Optimise-while-bodies-for-effect.patch --]
[-- Type: application/octet-stream, Size: 1291 bytes --]

From c8cdd32aac98721e2f543fe94134db32a280e371 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 26 Dec 2019 17:50:19 +0100
Subject: [PATCH] Optimise 'while' bodies for effect

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Treat all expressions in the body of 'while' as for-effect,
since their values are discarded.  This also finds some errors.
---
 lisp/emacs-lisp/byte-opt.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 22fea1b8da..07fd548dec 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -480,6 +480,13 @@ byte-optimize-form-code-walker
                                                  backwards)))))
 	     (cons fn (mapcar 'byte-optimize-form (cdr form)))))
 
+	  ((eq fn 'while)
+           (unless (consp (cdr form))
+	     (byte-compile-warn "too few arguments for `while'"))
+           (cons fn
+                 (cons (byte-optimize-form (cadr form) nil)
+                       (byte-optimize-body (cddr form) t))))
+
 	  ((eq fn 'interactive)
 	   (byte-compile-warn "misplaced interactive spec: `%s'"
 			      (prin1-to-string form))
-- 
2.21.0 (Apple Git-122.2)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-17 10:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-26 16:59 Optimise 'while' bodies for effect Mattias Engdegård
2019-12-26 18:19 ` Stefan Monnier
2019-12-26 18:46   ` Mattias Engdegård
2020-04-14 15:05     ` Basil L. Contovounesios
2020-04-16 10:52       ` Mattias Engdegård
2020-04-17 10:41         ` Basil L. Contovounesios

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.