diff options
| author | Paul Eggert | 2017-08-18 20:36:10 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-08-18 20:37:31 -0700 |
| commit | e73691e1a47834aff367c9131fc3c7d78751d821 (patch) | |
| tree | c1cf3cd0d4e99b8edaba6c13d53c5d762e0dc7e2 /lisp | |
| parent | e66e81679c3c91d6bf8f62c7abcd968430b4d1fe (diff) | |
| download | emacs-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.el | 20 |
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), | |||
| 1404 | is guaranteed to point to a newly created file. | 1404 | is guaranteed to point to a newly created file. |
| 1405 | You can then use `write-region' to write new data into the file. | 1405 | You can then use `write-region' to write new data into the file. |
| 1406 | 1406 | ||
| 1407 | If TEXT is non-nil, it will be inserted in the new file. Otherwise | ||
| 1408 | the file will be empty. | ||
| 1409 | |||
| 1410 | If DIR-FLAG is non-nil, create a new empty directory instead of a file. | 1407 | If DIR-FLAG is non-nil, create a new empty directory instead of a file. |
| 1411 | 1408 | ||
| 1412 | If SUFFIX is non-nil, add that at the end of the file name." | 1409 | If SUFFIX is non-nil, add that at the end of the file name. |
| 1410 | |||
| 1411 | If TEXT is a string, insert it into the new file; DIR-FLAG should be nil. | ||
| 1412 | Otherwise 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) |