]> git.eshelyaron.com Git - emacs.git/commitdiff
insert-file-contents file size hint improvement
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Jul 2025 23:03:29 +0000 (16:03 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 08:48:49 +0000 (10:48 +0200)
* src/fileio.c (Finsert_file_contents): When reading yields 0,
update the file size hint to match.  This should improve its
accuracy.

(cherry picked from commit de0bb2e059f1c404ca328509f3eb90cdf90256c5)

src/fileio.c

index b7b4320d73e6fff5066651bad9b97aecbfea0ccf..6292960b07b06acda34f63872ea7773ed2c4823d 100644 (file)
@@ -4668,6 +4668,7 @@ by calling `format-decode', which see.  */)
 
       inserted = 0;            /* Bytes put into CONVERSION_BUFFER so far.  */
       unprocessed = 0;         /* Bytes not processed in previous loop.  */
+      file_size_hint = beg_offset;
 
       while (true)
        {
@@ -4679,6 +4680,7 @@ by calling `format-decode', which see.  */)
          if (this <= 0)
            break;
 
+         file_size_hint += this;
          BUF_TEMP_SET_PT (XBUFFER (conversion_buffer),
                           BUF_Z (XBUFFER (conversion_buffer)));
          decode_coding_c_string (&coding, (unsigned char *) read_buf,
@@ -4934,6 +4936,8 @@ by calling `format-decode', which see.  */)
       }
   }
 
+  file_size_hint = beg_offset + inserted;
+
   /* Now we have either read all the file data into the gap,
      or stop reading on I/O error or quit.  If nothing was
      read, undo marking the buffer modified.  */