all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Artur Malabarba <bruce.connor.am@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Lazy printing in tabulated-list-mode
Date: Mon, 4 May 2015 11:46:28 +0100	[thread overview]
Message-ID: <CAAdUY-LD=dszhHFeGo+Pc9TeFiU6FhhywPaN_UWODOHVi4sneQ@mail.gmail.com> (raw)
In-Reply-To: <CAAdUY-JTrz1Cn0jXP5sZ0HR51WwS9oabChaq78DU5nf1c4YQVg@mail.gmail.com>

With some investigation, I managed to pinpoint some small problems in
-print-col: propertize and concat.
By replacing the calls to `propertize' with
insert+put-text-properties, and by removing the `concat', the
following patch speeds up printing by ~ 20%. The only functional
difference is that the help-echo property of an entry's column will be
"entry-content" instead of "column-name: entry-content" (the former
seems redundant to me anyway).

I get another 50% speed-up on top of that if I remove all
`put-text-property' calls. :-D I won't do that of course, but at least
it shows where most of the work is going.

Subject: [PATCH] * lisp/emacs-lisp/tabulated-list.el: Speed optimizations

(tabulated-list-print-col): Prefer `put-text-property' to
`propertize'.  Avoid `concat'.
---
 lisp/emacs-lisp/tabulated-list.el | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/lisp/emacs-lisp/tabulated-list.el
b/lisp/emacs-lisp/tabulated-list.el
index b12edc8..173e253 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -346,6 +346,14 @@ of column descriptors."
      beg (point)
      `(tabulated-list-id ,id tabulated-list-entry ,cols))))

+(defmacro tabulated-list--insert-space-string (s prop value)
+  "Insert a propertized string of size S composed of spaces.
+Put property PROP with VALUE."
+  `(let* ((size ,s)
+          (string (make-string size ?\s)))
+     (put-text-property 0 size ,prop ,value  string)
+     (insert string)))
+
 (defun tabulated-list-print-col (n col-desc x)
   "Insert a specified Tabulated List entry at point.
 N is the column number, COL-DESC is a column descriptor (see
@@ -361,7 +369,6 @@ Return the column number after insertion."
          (right-align (plist-get props :right-align))
      (label     (if (stringp col-desc) col-desc (car col-desc)))
          (label-width (string-width label))
-     (help-echo (concat (car format) ": " label))
      (opoint (point))
      (not-last-col (< (1+ n) (length tabulated-list-format))))
     ;; Truncate labels if necessary (except last column).
@@ -372,22 +379,24 @@ Return the column number after insertion."
     (setq label (bidi-string-mark-left-to-right label))
     (when (and right-align (> width label-width))
       (let ((shift (- width label-width)))
-        (insert (propertize (make-string shift ?\s)
-                            'display `(space :align-to ,(+ x shift))))
+        (tabulated-list--insert-space-string
+         shift 'display `(space :align-to ,(+ x shift)))
         (setq width (- width shift))
         (setq x (+ x shift))))
     (if (stringp col-desc)
-    (insert (if (get-text-property 0 'help-echo label)
-            label
-          (propertize label 'help-echo help-echo)))
+    (if (get-text-property 0 'help-echo label)
+            (insert label)
+          (let ((op (point)))
+            (insert label)
+            (put-text-property op (point) 'help-echo label)))
       (apply 'insert-text-button label (cdr col-desc)))
     (let ((next-x (+ x pad-right width)))
       ;; No need to append any spaces if this is the last column.
       (when not-last-col
         (when (> pad-right 0) (insert (make-string pad-right ?\s)))
-        (insert (propertize
-                 (make-string (- next-x x label-width pad-right) ?\s)
-                 'display `(space :align-to ,next-x))))
+        (tabulated-list--insert-space-string
+         (- next-x x label-width pad-right)
+         'display `(space :align-to ,next-x)))
       (put-text-property opoint (point) 'tabulated-list-column-name name)
       next-x)))

-- 
2.3.7



  reply	other threads:[~2015-05-04 10:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 16:11 Lazy printing in tabulated-list-mode Artur Malabarba
2015-04-30 16:13 ` Artur Malabarba
2015-05-01 13:43 ` Stefan Monnier
2015-05-01 14:03   ` Artur Malabarba
2015-05-01 17:27     ` Stefan Monnier
2015-05-01 18:11       ` Artur Malabarba
2015-05-01 18:12         ` Artur Malabarba
2015-05-01 18:31           ` Artur Malabarba
2015-05-01 20:46         ` Stefan Monnier
2015-05-02  9:38           ` Artur Malabarba
2015-05-03 16:21             ` Stefan Monnier
2015-05-03 17:02               ` Artur Malabarba
2015-05-04  0:19                 ` Stefan Monnier
2015-05-04  8:21                   ` Artur Malabarba
2015-05-04 10:46                     ` Artur Malabarba [this message]
2015-05-04 12:38                     ` Stefan Monnier

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='CAAdUY-LD=dszhHFeGo+Pc9TeFiU6FhhywPaN_UWODOHVi4sneQ@mail.gmail.com' \
    --to=bruce.connor.am@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.