summaryrefslogtreecommitdiff
path: root/src/region-cache.c
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2013-03-15 11:23:49 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2013-03-15 11:23:49 +0400
commitf258b4be0054dd0af7e52bbbbdbb776096ab3f8b (patch)
treea425ae33dfb8ab4498c3caf7a4ea3da16cabbdaa /src/region-cache.c
parentf35ffe5e3714cecdc5d7ea4027339178393cb578 (diff)
downloademacs-f258b4be0054dd0af7e52bbbbdbb776096ab3f8b.tar.gz
* region-cache.c (find_cache_boundary, move_cache_gap)
(insert_cache_boundary, delete_cache_boundaries, set_cache_region): Simplify debugging check and convert to eassert. Adjust comment. (pp_cache): Put under ENABLE_CHECKING.
Diffstat (limited to 'src/region-cache.c')
-rw-r--r--src/region-cache.c58
1 files changed, 20 insertions, 38 deletions
diff --git a/src/region-cache.c b/src/region-cache.c
index 452a5b3a065..be7d50a50e4 100644
--- a/src/region-cache.c
+++ b/src/region-cache.c
@@ -190,10 +190,9 @@ find_cache_boundary (struct region_cache *c, ptrdiff_t pos)
}
/* Some testing. */
- if (BOUNDARY_POS (c, low) > pos
- || (low + 1 < c->cache_len
- && BOUNDARY_POS (c, low + 1) <= pos))
- emacs_abort ();
+ eassert (!(BOUNDARY_POS (c, low) > pos
+ || (low + 1 < c->cache_len
+ && BOUNDARY_POS (c, low + 1) <= pos)));
return low;
}
@@ -214,14 +213,9 @@ move_cache_gap (struct region_cache *c, ptrdiff_t pos, ptrdiff_t min_size)
ptrdiff_t buffer_beg = c->buffer_beg;
ptrdiff_t buffer_end = c->buffer_end;
- if (pos < 0
- || pos > c->cache_len)
- emacs_abort ();
-
/* We mustn't ever try to put the gap before the dummy start
boundary. That must always be start-relative. */
- if (pos == 0)
- emacs_abort ();
+ eassert (0 < pos && pos <= c->cache_len);
/* Need we move the gap right? */
while (gap_start < pos)
@@ -288,26 +282,19 @@ static void
insert_cache_boundary (struct region_cache *c, ptrdiff_t i, ptrdiff_t pos,
int value)
{
- /* i must be a valid cache index. */
- if (i < 0 || i > c->cache_len)
- emacs_abort ();
-
- /* We must never want to insert something before the dummy first
- boundary. */
- if (i == 0)
- emacs_abort ();
+ /* I must be a valid cache index, and we must never want
+ to insert something before the dummy first boundary. */
+ eassert (0 < i && i <= c->cache_len);
/* We must only be inserting things in order. */
- if (! (BOUNDARY_POS (c, i - 1) < pos
- && (i == c->cache_len
- || pos < BOUNDARY_POS (c, i))))
- emacs_abort ();
+ eassert ((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)
- emacs_abort ();
+ eassert (BOUNDARY_VALUE (c, i - 1) != value);
move_cache_gap (c, i, 1);
@@ -328,18 +315,13 @@ delete_cache_boundaries (struct region_cache *c,
ptrdiff_t len = end - start;
/* Gotta be in range. */
- if (start < 0
- || end > c->cache_len)
- emacs_abort ();
+ eassert (0 <= start && end <= c->cache_len);
/* Gotta be in order. */
- if (start > end)
- emacs_abort ();
+ eassert (start <= end);
/* Can't delete the dummy entry. */
- if (start == 0
- && end >= 1)
- emacs_abort ();
+ eassert (!(start == 0 && end >= 1));
/* Minimize gap motion. If we're deleting nothing, do nothing. */
if (len == 0)
@@ -378,11 +360,8 @@ static void
set_cache_region (struct region_cache *c,
ptrdiff_t start, ptrdiff_t end, int value)
{
- if (start > end)
- emacs_abort ();
- if (start < c->buffer_beg
- || end > c->buffer_end)
- emacs_abort ();
+ eassert (start <= end);
+ eassert (c->buffer_beg <= start && end <= c->buffer_end);
/* Eliminate this case; then we can assume that start and end-1 are
both the locations of real characters in the buffer. */
@@ -772,7 +751,8 @@ int region_cache_backward (struct buffer *buf, struct region_cache *c,
}
}
-
+#ifdef ENABLE_CHECKING
+
/* Debugging: pretty-print a cache to the standard error output. */
void pp_cache (struct region_cache *) EXTERNALLY_VISIBLE;
@@ -803,3 +783,5 @@ pp_cache (struct region_cache *c)
fprintf (stderr, "%"pD"d : %d\n", pos, BOUNDARY_VALUE (c, i));
}
}
+
+#endif /* ENABLE_CHECKING */