summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-05-18 18:22:11 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2013-05-18 18:22:15 +0200
commitc22f5f632bc11e584d9df99efbbe37dfbf50d9af (patch)
treefc7531efc48df084ae05b1012b919188a1de9f0b
parent62296ceb8879efb4cd76ed3e00e8047ccf30777b (diff)
downloadorg-mode-c22f5f632bc11e584d9df99efbbe37dfbf50d9af.tar.gz
ox-ascii: Improve speed wrt table export
* lisp/ox-ascii.el (org-ascii--table-cell-width): Cache results of this internal function since it is called at each cell, though its value only change column wise.
-rw-r--r--lisp/ox-ascii.el48
1 files changed, 29 insertions, 19 deletions
diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index bdc54b2..1884061 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -1672,25 +1672,35 @@ column.
When `org-ascii-table-widen-columns' is non-nil, width cookies
are ignored."
- (or (and (not org-ascii-table-widen-columns)
- (org-export-table-cell-width table-cell info))
- (let* ((max-width 0)
- (table (org-export-get-parent-table table-cell))
- (specialp (org-export-table-has-special-column-p table))
- (col (cdr (org-export-table-cell-address table-cell info))))
- (org-element-map table 'table-row
- (lambda (row)
- (setq max-width
- (max (length
- (org-export-data
- (org-element-contents
- (elt (if specialp (cdr (org-element-contents row))
- (org-element-contents row))
- col))
- info))
- max-width)))
- info)
- max-width)))
+ (let* ((row (org-export-get-parent table-cell))
+ (table (org-export-get-parent row))
+ (col (let ((cells (org-element-contents row)))
+ (- (length cells) (length (memq table-cell cells)))))
+ (cache
+ (or (plist-get info :ascii-table-cell-width-cache)
+ (plist-get (setq info
+ (plist-put info :ascii-table-cell-width-cache
+ (make-hash-table :test 'equal)))
+ :ascii-table-cell-width-cache)))
+ (key (cons table col)))
+ (or (gethash key cache)
+ (puthash
+ key
+ (or (and (not org-ascii-table-widen-columns)
+ (org-export-table-cell-width table-cell info))
+ (let* ((max-width 0))
+ (org-element-map table 'table-row
+ (lambda (row)
+ (setq max-width
+ (max (length
+ (org-export-data
+ (org-element-contents
+ (elt (org-element-contents row) col))
+ info))
+ max-width)))
+ info)
+ max-width))
+ cache))))
(defun org-ascii-table-cell (table-cell contents info)
"Transcode a TABLE-CELL object from Org to ASCII.