aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPaul Eggert2017-08-18 20:36:10 -0700
committerPaul Eggert2017-08-18 20:37:31 -0700
commite73691e1a47834aff367c9131fc3c7d78751d821 (patch)
treec1cf3cd0d4e99b8edaba6c13d53c5d762e0dc7e2 /lisp
parente66e81679c3c91d6bf8f62c7abcd968430b4d1fe (diff)
downloademacs-e73691e1a47834aff367c9131fc3c7d78751d821.tar.gz
emacs-e73691e1a47834aff367c9131fc3c7d78751d821.zip
Improve make-temp-file performance on local files
* lisp/files.el (make-temp-file): Let make-temp-file-internal do the work of inserting the text. * src/fileio.c (Fmake_temp_file_internal): New arg TEXT. All callers changed.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el20
1 files changed, 8 insertions, 12 deletions
diff --git a/lisp/files.el b/lisp/files.el
index a2b474f8d2b..0311cc6d210 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1404,24 +1404,20 @@ of PREFIX, and expanding against `temporary-file-directory' if necessary),
1404is guaranteed to point to a newly created file. 1404is guaranteed to point to a newly created file.
1405You can then use `write-region' to write new data into the file. 1405You can then use `write-region' to write new data into the file.
1406 1406
1407If TEXT is non-nil, it will be inserted in the new file. Otherwise
1408the file will be empty.
1409
1410If DIR-FLAG is non-nil, create a new empty directory instead of a file. 1407If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1411 1408
1412If SUFFIX is non-nil, add that at the end of the file name." 1409If SUFFIX is non-nil, add that at the end of the file name.
1410
1411If TEXT is a string, insert it into the new file; DIR-FLAG should be nil.
1412Otherwise the file will be empty."
1413 (let ((absolute-prefix 1413 (let ((absolute-prefix
1414 (if (or (zerop (length prefix)) (member prefix '("." ".."))) 1414 (if (or (zerop (length prefix)) (member prefix '("." "..")))
1415 (concat (file-name-as-directory temporary-file-directory) prefix) 1415 (concat (file-name-as-directory temporary-file-directory) prefix)
1416 (expand-file-name prefix temporary-file-directory))) 1416 (expand-file-name prefix temporary-file-directory))))
1417 (contents (if (stringp text) text "")))
1418 (if (find-file-name-handler absolute-prefix 'write-region) 1417 (if (find-file-name-handler absolute-prefix 'write-region)
1419 (files--make-magic-temp-file absolute-prefix dir-flag suffix contents) 1418 (files--make-magic-temp-file absolute-prefix dir-flag suffix text)
1420 (let ((file (make-temp-file-internal absolute-prefix 1419 (make-temp-file-internal absolute-prefix
1421 (if dir-flag t) (or suffix "")))) 1420 (if dir-flag t) (or suffix "") text))))
1422 (when (and (stringp text) (not dir-flag))
1423 (write-region contents nil file nil 'silent))
1424 file))))
1425 1421
1426(defun files--make-magic-temp-file (absolute-prefix 1422(defun files--make-magic-temp-file (absolute-prefix
1427 &optional dir-flag suffix text) 1423 &optional dir-flag suffix text)