-Copyright (C) 1985-1989, 1993, 1995, 2001-2011
- Free Software Foundation, Inc.
+Copyright (C) 1985-1989, 1993, 1995, 2001-2013 Free Software Foundation,
+Inc.
/* The areas that haven't changed since the last time we cleaned out
invalid entries from the cache. These overlap when the buffer is
entirely unchanged. */
/* The areas that haven't changed since the last time we cleaned out
invalid entries from the cache. These overlap when the buffer is
entirely unchanged. */
/* The first and last positions in the buffer. Because boundaries
store their positions relative to the start (BEG) and end (Z) of
/* The first and last positions in the buffer. Because boundaries
store their positions relative to the start (BEG) and end (Z) of
Yes, buffer_beg is always 1. It's there for symmetry with
buffer_end and the BEG and BUF_BEG macros. */
Yes, buffer_beg is always 1. It's there for symmetry with
buffer_end and the BEG and BUF_BEG macros. */
This operation should be logarithmic in the number of cache
entries. It would be nice if it took advantage of locality of
reference, too, by searching entries near the last entry found. */
This operation should be logarithmic in the number of cache
entries. It would be nice if it took advantage of locality of
reference, too, by searching entries near the last entry found. */
- EMACS_INT mid = (low + high) >> 1;
- EMACS_INT boundary = BOUNDARY_POS (c, mid);
+ ptrdiff_t mid = (low >> 1) + (high >> 1) + (low & high & 1);
+ ptrdiff_t boundary = BOUNDARY_POS (c, mid);
if (BOUNDARY_POS (c, low) > pos
|| (low + 1 < c->cache_len
&& BOUNDARY_POS (c, low + 1) <= pos))
if (BOUNDARY_POS (c, low) > pos
|| (low + 1 < c->cache_len
&& BOUNDARY_POS (c, low + 1) <= pos))
/* Move the gap of cache C to index POS, and make sure it has space
for at least MIN_SIZE boundaries. */
static void
/* Move the gap of cache C to index POS, and make sure it has space
for at least MIN_SIZE boundaries. */
static void
- EMACS_INT gap_start = c->gap_start;
- EMACS_INT gap_len = c->gap_len;
- EMACS_INT buffer_beg = c->buffer_beg;
- EMACS_INT buffer_end = c->buffer_end;
+ ptrdiff_t gap_start = c->gap_start;
+ ptrdiff_t gap_len = c->gap_len;
+ ptrdiff_t buffer_beg = c->buffer_beg;
+ ptrdiff_t buffer_end = c->buffer_end;
/* We mustn't ever try to put the gap before the dummy start
boundary. That must always be start-relative. */
if (pos == 0)
/* We mustn't ever try to put the gap before the dummy start
boundary. That must always be start-relative. */
if (pos == 0)
- EMACS_INT i;
-
- /* Always make at least NEW_CACHE_GAP elements, as long as we're
- expanding anyway. */
- if (min_size < NEW_CACHE_GAP)
- min_size = NEW_CACHE_GAP;
+ ptrdiff_t i, nboundaries = c->cache_len;
- (struct boundary *) xrealloc (c->boundaries,
- ((min_size + c->cache_len)
- * sizeof (*c->boundaries)));
+ xpalloc (c->boundaries, &nboundaries, min_size - gap_len, -1,
+ sizeof *c->boundaries);
/* Some systems don't provide a version of the copy routine that
can be trusted to shift memory upward into an overlapping
region. memmove isn't widely available. */
/* Some systems don't provide a version of the copy routine that
can be trusted to shift memory upward into an overlapping
region. memmove isn't widely available. */
for (i = c->cache_len - 1; i >= gap_start; i--)
{
c->boundaries[i + min_size].pos = c->boundaries[i + gap_len].pos;
for (i = c->cache_len - 1; i >= gap_start; i--)
{
c->boundaries[i + min_size].pos = c->boundaries[i + gap_len].pos;
/* Insert a new boundary in cache C; it will have cache index I,
and have the specified POS and VALUE. */
static void
/* Insert a new boundary in cache C; it will have cache index I,
and have the specified POS and VALUE. */
static void
-insert_cache_boundary (struct region_cache *c, EMACS_INT i, EMACS_INT pos,
+insert_cache_boundary (struct region_cache *c, ptrdiff_t i, ptrdiff_t pos,
/* We must only be inserting things in order. */
if (! (BOUNDARY_POS (c, i - 1) < pos
&& (i == c->cache_len
|| pos < BOUNDARY_POS (c, i))))
/* We must only be inserting things in order. */
if (! (BOUNDARY_POS (c, i - 1) < pos
&& (i == c->cache_len
|| pos < BOUNDARY_POS (c, i))))
/* The value must be different from the ones around it. However, we
temporarily create boundaries that establish the same value as
the subsequent boundary, so we're not going to flag that case. */
if (BOUNDARY_VALUE (c, i - 1) == value)
/* The value must be different from the ones around it. However, we
temporarily create boundaries that establish the same value as
the subsequent boundary, so we're not going to flag that case. */
if (BOUNDARY_VALUE (c, i - 1) == value)
/* Set the value in cache C for the region START..END to VALUE. */
static void
set_cache_region (struct region_cache *c,
/* Set the value in cache C for the region START..END to VALUE. */
static void
set_cache_region (struct region_cache *c,
/* Eliminate this case; then we can assume that start and end-1 are
both the locations of real characters in the buffer. */
/* Eliminate this case; then we can assume that start and end-1 are
both the locations of real characters in the buffer. */
index of the earliest boundary after the last character in
start..end. (This tortured terminology is intended to answer
all the "< or <=?" sort of questions.) */
index of the earliest boundary after the last character in
start..end. (This tortured terminology is intended to answer
all the "< or <=?" sort of questions.) */
- EMACS_INT start_ix = find_cache_boundary (c, start);
- EMACS_INT end_ix = find_cache_boundary (c, end - 1) + 1;
+ ptrdiff_t start_ix = find_cache_boundary (c, start);
+ ptrdiff_t end_ix = find_cache_boundary (c, end - 1) + 1;
/* We must remember the value established by the last boundary
before end; if that boundary's domain stretches beyond end,
/* We must remember the value established by the last boundary
before end; if that boundary's domain stretches beyond end,
args to pass are the same before and after such an operation.) */
void
invalidate_region_cache (struct buffer *buf, struct region_cache *c,
args to pass are the same before and after such an operation.) */
void
invalidate_region_cache (struct buffer *buf, struct region_cache *c,
{
/* Let chead = c->beg_unchanged, and
ctail = c->end_unchanged.
{
/* Let chead = c->beg_unchanged, and
ctail = c->end_unchanged.
no newlines", in the case of the line cache). */
void
know_region_cache (struct buffer *buf, struct region_cache *c,
no newlines", in the case of the line cache). */
void
know_region_cache (struct buffer *buf, struct region_cache *c,
/* Return true if the text immediately after POS in BUF is known, for
the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest
/* Return true if the text immediately after POS in BUF is known, for
the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest
/* Return true if the text immediately before POS in BUF is known, for
the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest
/* Return true if the text immediately before POS in BUF is known, for
the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest
- int i;
- EMACS_INT beg_u = c->buffer_beg + c->beg_unchanged;
- EMACS_INT end_u = c->buffer_end - c->end_unchanged;
+ ptrdiff_t i;
+ ptrdiff_t beg_u = c->buffer_beg + c->beg_unchanged;
+ ptrdiff_t end_u = c->buffer_end - c->end_unchanged;
c->buffer_beg, c->buffer_end,
beg_u, end_u);
for (i = 0; i < c->cache_len; i++)
{
c->buffer_beg, c->buffer_end,
beg_u, end_u);
for (i = 0; i < c->cache_len; i++)
{
- fprintf (stderr, "%"pI"d : %d\n", pos, BOUNDARY_VALUE (c, i));
+ fprintf (stderr, "%"pD"d : %d\n", pos, BOUNDARY_VALUE (c, i));