Skip to content

Commit 415c90a

Browse files
author
Jason Duncan
committed
Further eliminating concatenation during rendering to save for the very end.
1 parent af23fad commit 415c90a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

format-table.el

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,29 @@ Arguments are the list of values ROW, the list of MAX-COL-WIDTHS, and delimiter
172172
information in OUTPUT-MODE. Optionally use PAD-FN to pad each column value,
173173
otherwise values will be padded to the right with spaces."
174174
(let ((pad-fn (or pad-fn #'format-table-pad-right)))
175-
(list
176-
(plist-get output-mode :begin-row)
177-
(string-join
178-
(-zip-with pad-fn row max-col-widths)
179-
(plist-get output-mode :col-separator))
180-
(plist-get output-mode :end-row)
181-
hard-newline)))
175+
(append
176+
(list
177+
(plist-get output-mode :begin-row))
178+
(-interpose (plist-get output-mode :col-separator)
179+
(-zip-with pad-fn row max-col-widths))
180+
(list
181+
(plist-get output-mode :end-row)
182+
hard-newline))))
182183

183184
(defun format-table-generate-dash-string (length)
184185
"Generate a string of hyphens LENGTH chars long."
185186
(make-string length ?-))
186187

187188
(defun format-table-render-separator-row (max-col-widths output-mode)
188189
"Given the list of MAX-COL-WIDTHS and delimiter information in OUTPUT-MODE, render a row which separates the header row from the rest of the rows."
189-
(list
190-
(plist-get output-mode :separator-begin-row)
191-
(string-join
192-
(-map #'format-table-generate-dash-string max-col-widths)
193-
(plist-get output-mode :separator-col-separator))
194-
(plist-get output-mode :separator-end-row)
195-
hard-newline))
190+
(append
191+
(list
192+
(plist-get output-mode :separator-begin-row))
193+
(-interpose (plist-get output-mode :separator-col-separator)
194+
(-map #'format-table-generate-dash-string max-col-widths))
195+
(list
196+
(plist-get output-mode :separator-end-row)
197+
hard-newline)))
196198

197199
(defun format-table-render-json (table)
198200
"Render the TABLE of values as a json string."

0 commit comments

Comments
 (0)