emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lazy printing in tabulated-list-mode


From: Artur Malabarba
Subject: Re: Lazy printing in tabulated-list-mode
Date: Mon, 4 May 2015 11:46:28 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]