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 /src | |
| 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 'src')
| -rw-r--r-- | src/fileio.c | 22 | ||||
| -rw-r--r-- | src/filelock.c | 2 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/fileio.c b/src/fileio.c index 1b832be344d..6b3bdf2154d 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -657,18 +657,20 @@ In Unix-syntax, this function just removes the final slash. */) | |||
| 657 | } | 657 | } |
| 658 | 658 | ||
| 659 | DEFUN ("make-temp-file-internal", Fmake_temp_file_internal, | 659 | DEFUN ("make-temp-file-internal", Fmake_temp_file_internal, |
| 660 | Smake_temp_file_internal, 3, 3, 0, | 660 | Smake_temp_file_internal, 4, 4, 0, |
| 661 | doc: /* Generate a new file whose name starts with PREFIX, a string. | 661 | doc: /* Generate a new file whose name starts with PREFIX, a string. |
| 662 | Return the name of the generated file. If DIR-FLAG is zero, do not | 662 | Return the name of the generated file. If DIR-FLAG is zero, do not |
| 663 | create the file, just its name. Otherwise, if DIR-FLAG is non-nil, | 663 | create the file, just its name. Otherwise, if DIR-FLAG is non-nil, |
| 664 | create an empty directory. The file name should end in SUFFIX. | 664 | create an empty directory. The file name should end in SUFFIX. |
| 665 | Do not expand PREFIX; a non-absolute PREFIX is relative to the Emacs | 665 | Do not expand PREFIX; a non-absolute PREFIX is relative to the Emacs |
| 666 | working directory. | 666 | working directory. If TEXT is a string, insert it into the newly |
| 667 | created file. | ||
| 667 | 668 | ||
| 668 | Signal an error if the file could not be created. | 669 | Signal an error if the file could not be created. |
| 669 | 670 | ||
| 670 | This function does not grok magic file names. */) | 671 | This function does not grok magic file names. */) |
| 671 | (Lisp_Object prefix, Lisp_Object dir_flag, Lisp_Object suffix) | 672 | (Lisp_Object prefix, Lisp_Object dir_flag, Lisp_Object suffix, |
| 673 | Lisp_Object text) | ||
| 672 | { | 674 | { |
| 673 | CHECK_STRING (prefix); | 675 | CHECK_STRING (prefix); |
| 674 | CHECK_STRING (suffix); | 676 | CHECK_STRING (suffix); |
| @@ -688,7 +690,15 @@ This function does not grok magic file names. */) | |||
| 688 | : EQ (dir_flag, make_number (0)) ? GT_NOCREATE | 690 | : EQ (dir_flag, make_number (0)) ? GT_NOCREATE |
| 689 | : GT_DIR); | 691 | : GT_DIR); |
| 690 | int fd = gen_tempname (data, suffix_len, O_BINARY | O_CLOEXEC, kind); | 692 | int fd = gen_tempname (data, suffix_len, O_BINARY | O_CLOEXEC, kind); |
| 691 | if (fd < 0 || (NILP (dir_flag) && emacs_close (fd) != 0)) | 693 | bool failed = fd < 0; |
| 694 | if (!failed) | ||
| 695 | { | ||
| 696 | val = DECODE_FILE (val); | ||
| 697 | if (STRINGP (text) && SBYTES (text) != 0) | ||
| 698 | write_region (text, Qnil, val, Qnil, Qnil, Qnil, Qnil, fd); | ||
| 699 | failed = NILP (dir_flag) && emacs_close (fd) != 0; | ||
| 700 | } | ||
| 701 | if (failed) | ||
| 692 | { | 702 | { |
| 693 | static char const kind_message[][32] = | 703 | static char const kind_message[][32] = |
| 694 | { | 704 | { |
| @@ -698,7 +708,7 @@ This function does not grok magic file names. */) | |||
| 698 | }; | 708 | }; |
| 699 | report_file_error (kind_message[kind], prefix); | 709 | report_file_error (kind_message[kind], prefix); |
| 700 | } | 710 | } |
| 701 | return DECODE_FILE (val); | 711 | return val; |
| 702 | } | 712 | } |
| 703 | 713 | ||
| 704 | 714 | ||
| @@ -715,7 +725,7 @@ For that reason, you should normally use `make-temp-file' instead. */) | |||
| 715 | (Lisp_Object prefix) | 725 | (Lisp_Object prefix) |
| 716 | { | 726 | { |
| 717 | return Fmake_temp_file_internal (prefix, make_number (0), | 727 | return Fmake_temp_file_internal (prefix, make_number (0), |
| 718 | empty_unibyte_string); | 728 | empty_unibyte_string, Qnil); |
| 719 | } | 729 | } |
| 720 | 730 | ||
| 721 | DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | 731 | DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, |
diff --git a/src/filelock.c b/src/filelock.c index fec9bc044ae..fd4f0aa864e 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -210,7 +210,7 @@ get_boot_time (void) | |||
| 210 | names up to 8 bytes long. Choose a 2 byte prefix, so | 210 | names up to 8 bytes long. Choose a 2 byte prefix, so |
| 211 | the 6-byte suffix does not make the name too long. */ | 211 | the 6-byte suffix does not make the name too long. */ |
| 212 | filename = Fmake_temp_file_internal (build_string ("wt"), Qnil, | 212 | filename = Fmake_temp_file_internal (build_string ("wt"), Qnil, |
| 213 | empty_unibyte_string); | 213 | empty_unibyte_string, Qnil); |
| 214 | CALLN (Fcall_process, build_string ("gzip"), Qnil, | 214 | CALLN (Fcall_process, build_string ("gzip"), Qnil, |
| 215 | list2 (QCfile, filename), Qnil, | 215 | list2 (QCfile, filename), Qnil, |
| 216 | build_string ("-cd"), tempname); | 216 | build_string ("-cd"), tempname); |