From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Ted Zlatanov <tzz@lifelogs.com>
Cc: emacs-devel@gnu.org
Subject: Re: view/edit large files
Date: Tue, 17 Feb 2009 14:23:32 -0500 [thread overview]
Message-ID: <jwvhc2s9aio.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <864oz2l47t.fsf@lifelogs.com> (Ted Zlatanov's message of "Tue, 10 Feb 2009 09:08:22 -0600")
> While time values and file offsets can certainly be represented as
> floats under some constraints, I think it's an inelegant solution.
> This is the chance to have a clean design for support of large integers,
> since I or someone else will be modifying insert-file-contents anyhow.
Using floats has the major advantage that it only requires changes in
insert-file-contents (e.g. try the patch below). Large integers can be
added as well, but it's a mostly orthogonal issue.
Stefan
=== modified file 'src/fileio.c'
--- src/fileio.c 2009-02-11 20:00:50 +0000
+++ src/fileio.c 2009-02-17 19:21:59 +0000
@@ -3161,6 +3161,7 @@
Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark;
int we_locked_file = 0;
int deferred_remove_unwind_protect = 0;
+ off_t beg_offset, end_offset;
if (current_buffer->base_buffer && ! NILP (visit))
error ("Cannot do file visiting in an indirect buffer");
@@ -3268,12 +3269,12 @@
}
if (!NILP (beg))
- CHECK_NUMBER (beg);
+ CHECK_NUMBER_OR_FLOAT (beg);
else
XSETFASTINT (beg, 0);
if (!NILP (end))
- CHECK_NUMBER (end);
+ CHECK_NUMBER_OR_FLOAT (end);
else
{
if (! not_regular)
@@ -3408,6 +3409,8 @@
set_coding_system = 1;
}
+ beg_offset = FLOATP (beg) ? (off_t) XFLOAT_DATA (beg) : XINT (beg);
+ end_offset = FLOATP (end) ? (off_t) XFLOAT_DATA (end) : XINT (end);
/* If requested, replace the accessible part of the buffer
with the file contents. Avoid replacing text at the
beginning or end of the buffer that matches the file contents;
@@ -3438,9 +3441,9 @@
give up on handling REPLACE in the optimized way. */
int giveup_match_end = 0;
- if (XINT (beg) != 0)
+ if (beg_offset != 0)
{
- if (lseek (fd, XINT (beg), 0) < 0)
+ if (lseek (fd, beg_offset, 0) < 0)
report_file_error ("Setting file position",
Fcons (orig_filename, Qnil));
}
@@ -3487,7 +3490,7 @@
immediate_quit = 0;
/* If the file matches the buffer completely,
there's no need to replace anything. */
- if (same_at_start - BEGV_BYTE == XINT (end))
+ if (same_at_start - BEGV_BYTE == end_offset - beg_offset)
{
emacs_close (fd);
specpdl_ptr--;
@@ -3505,7 +3508,7 @@
EMACS_INT total_read, nread, bufpos, curpos, trial;
/* At what file position are we now scanning? */
- curpos = XINT (end) - (ZV_BYTE - same_at_end);
+ curpos = end_offset - (ZV_BYTE - same_at_end);
/* If the entire file matches the buffer tail, stop the scan. */
if (curpos == 0)
break;
@@ -3583,8 +3586,8 @@
same_at_end += overlap;
/* Arrange to read only the nonmatching middle part of the file. */
- XSETFASTINT (beg, XINT (beg) + (same_at_start - BEGV_BYTE));
- XSETFASTINT (end, XINT (end) - (ZV_BYTE - same_at_end));
+ beg_offset += same_at_start - BEGV_BYTE;
+ end_offset -= ZV_BYTE - same_at_end;
del_range_byte (same_at_start, same_at_end, 0);
/* Insert from the file at the proper position. */
@@ -3628,7 +3631,7 @@
/* First read the whole file, performing code conversion into
CONVERSION_BUFFER. */
- if (lseek (fd, XINT (beg), 0) < 0)
+ if (lseek (fd, beg_offset, 0) < 0)
report_file_error ("Setting file position",
Fcons (orig_filename, Qnil));
@@ -3803,7 +3806,7 @@
{
register Lisp_Object temp;
- total = XINT (end) - XINT (beg);
+ total = end_offset - beg_offset;
/* Make sure point-max won't overflow after this insertion. */
XSETINT (temp, total);
@@ -3830,9 +3833,9 @@
if (GAP_SIZE < total)
make_gap (total - GAP_SIZE);
- if (XINT (beg) != 0 || !NILP (replace))
+ if (beg_offset != 0 || !NILP (replace))
{
- if (lseek (fd, XINT (beg), 0) < 0)
+ if (lseek (fd, beg_offset, 0) < 0)
report_file_error ("Setting file position",
Fcons (orig_filename, Qnil));
}
next prev parent reply other threads:[~2009-02-17 19:23 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-02 17:20 map-file-lines Ted Zlatanov
2009-02-02 18:54 ` map-file-lines Stefan Monnier
2009-02-02 19:22 ` map-file-lines Ted Zlatanov
2009-02-02 19:52 ` map-file-lines joakim
2009-02-02 20:54 ` map-file-lines Ted Zlatanov
2009-02-02 22:42 ` map-file-lines Stefan Monnier
2009-02-03 13:57 ` map-file-lines Ted Zlatanov
2009-02-02 22:41 ` map-file-lines Stefan Monnier
2009-02-02 23:59 ` map-file-lines joakim
2009-02-03 4:13 ` map-file-lines Stefan Monnier
2009-02-03 7:27 ` map-file-lines joakim
2009-02-03 14:50 ` map-file-lines Stefan Monnier
2009-02-04 7:04 ` map-file-lines Richard M Stallman
2009-02-04 15:38 ` map-file-lines Ted Zlatanov
2009-02-05 5:40 ` map-file-lines Richard M Stallman
2009-02-06 18:42 ` view/edit large files (was: map-file-lines) Ted Zlatanov
2009-02-06 21:06 ` view/edit large files Ted Zlatanov
2009-02-06 21:49 ` Miles Bader
[not found] ` <864oz3nyj8.fsf@lifelogs.com>
2009-02-10 1:58 ` Stefan Monnier
2009-02-10 8:46 ` Eli Zaretskii
2009-02-10 9:23 ` Miles Bader
2009-02-10 9:54 ` Eli Zaretskii
2009-02-10 10:02 ` Miles Bader
2009-02-10 11:50 ` Eli Zaretskii
2009-02-10 15:08 ` Ted Zlatanov
2009-02-17 19:23 ` Stefan Monnier [this message]
2009-02-17 19:47 ` Eli Zaretskii
2009-02-17 20:18 ` Miles Bader
2009-02-17 20:51 ` Eli Zaretskii
2009-02-17 21:19 ` Miles Bader
2009-02-17 21:21 ` Miles Bader
2009-02-18 4:09 ` Eli Zaretskii
2009-02-18 1:56 ` Stefan Monnier
2009-02-20 19:23 ` Ted Zlatanov
2009-02-10 12:28 ` Eli Zaretskii
2009-02-10 12:46 ` Miles Bader
2009-02-07 9:14 ` view/edit large files (was: map-file-lines) Richard M Stallman
2009-02-09 20:26 ` view/edit large files Ted Zlatanov
2009-02-10 20:02 ` Richard M Stallman
2009-02-06 13:20 ` map-file-lines Mathias Dahl
2009-02-02 22:40 ` map-file-lines Stefan Monnier
2009-02-03 4:11 ` map-file-lines Stefan Monnier
2009-02-02 20:48 ` map-file-lines Ted Zlatanov
2009-02-03 8:08 ` map-file-lines Thien-Thi Nguyen
2009-02-03 14:00 ` map-file-lines Ted Zlatanov
2009-02-03 14:17 ` map-file-lines Miles Bader
2009-02-03 10:45 ` map-file-lines Thierry Volpiatto
2009-02-03 14:06 ` map-file-lines Ted Zlatanov
2009-02-03 14:56 ` map-file-lines Thierry Volpiatto
-- strict thread matches above, loose matches on Subject: below --
2009-02-07 3:44 view/edit large files (was: map-file-lines) MON KEY
2009-02-08 4:34 ` Bob Rogers
2009-02-09 19:44 ` view/edit large files Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvhc2s9aio.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=tzz@lifelogs.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).