diff options
| author | Paul Eggert | 2025-07-16 11:16:13 -0700 |
|---|---|---|
| committer | Paul Eggert | 2025-07-16 11:45:23 -0700 |
| commit | 92dee45c5e4e7be1682a8a3aacdfd7d9c87cf286 (patch) | |
| tree | 900e2ff0e17ac4f6cc3b8e39ba2abf6d337743e3 | |
| parent | 8a1d368b6241d999668086fed3c20f634b9fb4d3 (diff) | |
| download | emacs-92dee45c5e4e7be1682a8a3aacdfd7d9c87cf286.tar.gz emacs-92dee45c5e4e7be1682a8a3aacdfd7d9c87cf286.zip | |
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.
| -rw-r--r-- | src/fileio.c | 28 |
1 files changed, 12 insertions, 16 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. */) | |||
| 4255 | 4255 | ||
| 4256 | /* Check now whether the buffer will become too large, | 4256 | /* Check now whether the buffer will become too large, |
| 4257 | in the likely case where the file's length is not changing. | 4257 | in the likely case where the file's length is not changing. |
| 4258 | This saves a lot of needless work before a buffer overflow. */ | 4258 | This saves a lot of needless work before a buffer overflow. |
| 4259 | if (regular) | 4259 | If LIKELY_END is nonnegative, it is likely where we will stop reading. |
| 4260 | { | 4260 | We could read more (or less), if the file grows (or shrinks). */ |
| 4261 | /* The likely offset where we will stop reading. We could read | 4261 | off_t likely_end = min (end_offset, file_size_hint); |
| 4262 | more (or less), if the file grows (or shrinks) as we read it. */ | 4262 | if (beg_offset < likely_end) |
| 4263 | off_t likely_end = min (end_offset, file_size_hint); | 4263 | { |
| 4264 | 4264 | ptrdiff_t buf_bytes | |
| 4265 | if (beg_offset < likely_end) | 4265 | = Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0); |
| 4266 | { | 4266 | ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes; |
| 4267 | ptrdiff_t buf_bytes | 4267 | off_t likely_growth = likely_end - beg_offset; |
| 4268 | = Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0); | 4268 | if (buf_growth_max < likely_growth) |
| 4269 | ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes; | 4269 | buffer_overflow (); |
| 4270 | off_t likely_growth = likely_end - beg_offset; | ||
| 4271 | if (buf_growth_max < likely_growth) | ||
| 4272 | buffer_overflow (); | ||
| 4273 | } | ||
| 4274 | } | 4270 | } |
| 4275 | 4271 | ||
| 4276 | /* Prevent redisplay optimizations. */ | 4272 | /* Prevent redisplay optimizations. */ |