summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2025-07-16 11:16:13 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2025-07-16 11:45:23 -0700
commit92dee45c5e4e7be1682a8a3aacdfd7d9c87cf286 (patch)
tree900e2ff0e17ac4f6cc3b8e39ba2abf6d337743e3 /src
parent8a1d368b6241d999668086fed3c20f634b9fb4d3 (diff)
insert-file-contents likely-end memory objects
* src/fileio.c (Finsert_file_contents): Treat memory objects like regular files when inferring likely end. Simplify likely end computation.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/fileio.c b/src/fileio.c
index e20249379e7..2c8855dba91 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4255,22 +4255,18 @@ by calling `format-decode', which see. */)
/* Check now whether the buffer will become too large,
in the likely case where the file's length is not changing.
- This saves a lot of needless work before a buffer overflow. */
- if (regular)
+ This saves a lot of needless work before a buffer overflow.
+ If LIKELY_END is nonnegative, it is likely where we will stop reading.
+ We could read more (or less), if the file grows (or shrinks). */
+ off_t likely_end = min (end_offset, file_size_hint);
+ if (beg_offset < likely_end)
{
- /* The likely offset where we will stop reading. We could read
- more (or less), if the file grows (or shrinks) as we read it. */
- off_t likely_end = min (end_offset, file_size_hint);
-
- if (beg_offset < likely_end)
- {
- ptrdiff_t buf_bytes
- = Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0);
- ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes;
- off_t likely_growth = likely_end - beg_offset;
- if (buf_growth_max < likely_growth)
- buffer_overflow ();
- }
+ ptrdiff_t buf_bytes
+ = Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0);
+ ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes;
+ off_t likely_growth = likely_end - beg_offset;
+ if (buf_growth_max < likely_growth)
+ buffer_overflow ();
}
/* Prevent redisplay optimizations. */