all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Shigeru Fukaya <shigeru.fukaya@gmail.com>
Cc: 14769@debbugs.gnu.org
Subject: bug#14769: 24.3.50; [PATCH] optimize `concat's literals
Date: Wed, 24 Feb 2016 15:51:00 +1100	[thread overview]
Message-ID: <87h9gyhft7.fsf@gnus.org> (raw)
In-Reply-To: <C9CE77463644E9shigeru.fukaya@gmail.com> (Shigeru Fukaya's message of "Wed, 03 Jul 2013 02:04:28 +0900")

Shigeru Fukaya <shigeru.fukaya@gmail.com> writes:

> Current bytecode optimizer works only when all arguments are
> constants.
>
> With the attached small patch, adjacent successive literal arguments
> of `concat' will become optimized to a string respectively.
>
> 	Make successive literals of `concat' optimized to a string.
> 	* byte-opt.el (byte-optimize-form-code-walker): call
> 	byte-optimize-concat-args for `concat'.
> 	(byte-optimize-concat-args): New function.

I think the patch below looks sensible, but the bytecode optimiser is
not something I'm familiar with.  Does this look OK to all y'all?

>
> Regards,
> Shigeru
>
> *** byte-opt.el	Fri Jun 14 19:32:39 2013
> --- byte-opt.new.el	Wed Jul  3 01:48:29 2013
> ***************
> *** 562,568 ****
>   	     (if (and (get fn 'pure)
>   		      (byte-optimize-all-constp args))
>   		   (list 'quote (apply fn (mapcar #'eval args)))
> ! 	       (cons fn args)))))))
>   
>   (defun byte-optimize-all-constp (list)
>     "Non-nil if all elements of LIST satisfy `macroexp-const-p"
> --- 562,572 ----
>   	     (if (and (get fn 'pure)
>   		      (byte-optimize-all-constp args))
>   		   (list 'quote (apply fn (mapcar #'eval args)))
> ! 	       (if (eq fn 'concat)
> ! 		   ;; Not all arguments are literals.
> ! 		   (cons fn (byte-optimize-concat-args args))
> ! 		 ;; Other than `concat'.
> ! 		 (cons fn args))))))))
>   
>   (defun byte-optimize-all-constp (list)
>     "Non-nil if all elements of LIST satisfy `macroexp-const-p"
> ***************
> *** 573,578 ****
> --- 577,605 ----
>         (setq list (cdr list)))
>       constant))
>   
> + (defun byte-optimize-concat-args (args)
> +   ;;
> +   ;; Convert arguments of `concat' such that adjacent successive
> +   ;; literal arguments to one string, and remove null strings.
> +   ;;
> +   (let (newargs)
> +     (while args
> +       ;; loop for literals
> +       (let (l)
> + 	(while (and args (macroexp-const-p (car args)))
> + 	  (push (car args) l)
> + 	  (setq args (cdr args)))
> + 	(when l
> + 	  (let ((s (apply #'concat (mapcar #'eval (nreverse l)))))
> + 	    ;; keep non-null string
> + 	    (unless (equal s "")
> + 	      (push s newargs)))))
> +       ;; non-literal argument
> +       (when args
> + 	(push (car args) newargs)
> + 	(setq args (cdr args))))
> +     (nreverse newargs)))
> + 
>   (defun byte-optimize-form (form &optional for-effect)
>     "The source-level pass of the optimizer."
>     ;;
>

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2016-02-24  4:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02 17:04 bug#14769: 24.3.50; [PATCH] optimize `concat's literals Shigeru Fukaya
2016-02-24  4:51 ` Lars Ingebrigtsen [this message]
2019-06-16 11:57 ` bug#14769: " Mattias Engdegård
2019-06-19  1:43   ` Noam Postavsky
2019-06-19 12:54     ` Mattias Engdegård
2019-06-20  0:38       ` Noam Postavsky
2019-06-21  9:07         ` Mattias Engdegård
2019-06-22 22:17           ` Noam Postavsky
2019-06-26  9:44             ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h9gyhft7.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=14769@debbugs.gnu.org \
    --cc=shigeru.fukaya@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.