aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2025-07-13 13:33:27 -0700
committerPaul Eggert2025-07-13 21:09:40 -0700
commit5bce6753e24d04ea3e4715fab53cc65c1b4ee8d7 (patch)
tree1dff0b49f0123e6e6dca0c7b09ea332e2032f781
parentc3f96d20eecdf0aa93f294a4f3fb96e16eec6a68 (diff)
downloademacs-5bce6753e24d04ea3e4715fab53cc65c1b4ee8d7.tar.gz
emacs-5bce6753e24d04ea3e4715fab53cc65c1b4ee8d7.zip
Speed up insert-file-contents reads
This change makes insert-file-contents-literally 30% faster on my platform, when inserting xdisp.c. * src/fileio.c (READ_BUF_SIZE): Remove, replacing with ... (IO_BUFSIZE): ... this new constant from Coreutils. All uses of READ_BUF_SIZE changed to either MAX_ALLOCA or IO_BUFSIZE.
-rw-r--r--src/fileio.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 075b9c590c8..8e1ac42723d 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3836,8 +3836,6 @@ For existing files, this compares their last-modified times. */)
3836 ? Qt : Qnil); 3836 ? Qt : Qnil);
3837} 3837}
3838 3838
3839enum { READ_BUF_SIZE = MAX_ALLOCA };
3840
3841/* This function is called after Lisp functions to decide a coding 3839/* This function is called after Lisp functions to decide a coding
3842 system are called, or when they cause an error. Before they are 3840 system are called, or when they cause an error. Before they are
3843 called, the current buffer is set unibyte and it contains only a 3841 called, the current buffer is set unibyte and it contains only a
@@ -4028,6 +4026,10 @@ maybe_move_gap (struct buffer *b)
4028 } 4026 }
4029} 4027}
4030 4028
4029/* A good blocksize to minimize system call overhead across most systems.
4030 Taken from coreutils/src/ioblksize.h as of July 2025. */
4031enum { IO_BUFSIZE = 256 * 1024 };
4032
4031/* FIXME: insert-file-contents should be split with the top-level moved to 4033/* FIXME: insert-file-contents should be split with the top-level moved to
4032 Elisp and only the core kept in C. */ 4034 Elisp and only the core kept in C. */
4033 4035
@@ -4082,7 +4084,7 @@ by calling `format-decode', which see. */)
4082 off_t total = 0; 4084 off_t total = 0;
4083 bool regular; 4085 bool regular;
4084 int save_errno = 0; 4086 int save_errno = 0;
4085 char read_buf[READ_BUF_SIZE]; 4087 char read_buf[MAX_ALLOCA];
4086 struct coding_system coding; 4088 struct coding_system coding;
4087 bool replace_handled = false; 4089 bool replace_handled = false;
4088 bool set_coding_system = false; 4090 bool set_coding_system = false;
@@ -4861,7 +4863,7 @@ by calling `format-decode', which see. */)
4861 else 4863 else
4862 { 4864 {
4863 buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted; 4865 buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted;
4864 bufsize = min (min (gap_size, total - inserted), READ_BUF_SIZE); 4866 bufsize = min (min (gap_size, total - inserted), IO_BUFSIZE);
4865 } 4867 }
4866 4868
4867 if (!seekable && end_offset == TYPE_MAXIMUM (off_t)) 4869 if (!seekable && end_offset == TYPE_MAXIMUM (off_t))