Instead of `nreverse'ing twice (a rather expensive operation) to trim a measly trailing newline, use `split-string's OMIT-NULLS argument to remove *all* zero-length lines (or none...).
Signed-off-by: Pieter Praet <[email protected]> --- magit.el | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/magit.el b/magit.el index 324fcfa..ac5aa39 100644 --- a/magit.el +++ b/magit.el @@ -1087,16 +1087,13 @@ (defun magit-file-line (file) (buffer-substring-no-properties (point-min) (line-end-position))))) -(defun magit-file-lines (file) +(defun magit-file-lines (file &optional keep-empty-lines) "Return a list of strings containing one element per line in FILE. -If the last line is empty, it's trimmed." +Unless optional argument KEEP-EMPTY-LINES is t, trim all empty lines." (when (file-regular-p file) (with-temp-buffer (insert-file-contents file) - (let ((rev (nreverse (split-string (buffer-string) "\n")))) - (nreverse (if (equal (car rev) "") - (cdr rev) - rev)))))) + (split-string (buffer-string) "\n" (not keep-empty-lines))))) (defun magit-put-line-property (prop val) (put-text-property (line-beginning-position) (line-beginning-position 2) -- 1.7.11.1 -- --- You received this message because you are subscribed to the Google Groups "magit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
