aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2014-04-23 18:21:25 +0300
committerEli Zaretskii2014-04-23 18:21:25 +0300
commit80d982d7ad6bbaab40731b60756da0f126311be0 (patch)
tree57e1639296b4cab531edf502e0cb02cb69153662 /src
parent05452dc497b4de96edc7379f52c9863696e1c297 (diff)
downloademacs-80d982d7ad6bbaab40731b60756da0f126311be0.tar.gz
emacs-80d982d7ad6bbaab40731b60756da0f126311be0.zip
Fix debugging code for checking the newline cache.
src/search.c (Fnewline_cache_check): Don't try to count newlines outside the buffer's restriction, as find_newline doesn't support that.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/search.c56
2 files changed, 43 insertions, 19 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6e2f7057b75..0c8fa7b31d7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12014-04-23 Eli Zaretskii <eliz@gnu.org>
2
3 * search.c (Fnewline_cache_check): Don't try to count newlines
4 outside the buffer's restriction, as find_newline doesn't support
5 that.
6
12014-04-22 Paul Eggert <eggert@cs.ucla.edu> 72014-04-22 Paul Eggert <eggert@cs.ucla.edu>
2 8
3 Port to GCC 4.9.0 with --enable-gcc-warnings. 9 Port to GCC 4.9.0 with --enable-gcc-warnings.
diff --git a/src/search.c b/src/search.c
index ab390faf82e..0a693daa15e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3209,7 +3209,7 @@ the first based on the cache, the second based on actually scanning
3209the buffer. If the buffer doesn't have a cache, the value is nil. */) 3209the buffer. If the buffer doesn't have a cache, the value is nil. */)
3210 (Lisp_Object buffer) 3210 (Lisp_Object buffer)
3211{ 3211{
3212 struct buffer *buf; 3212 struct buffer *buf, *old = NULL;
3213 ptrdiff_t shortage, nl_count_cache, nl_count_buf; 3213 ptrdiff_t shortage, nl_count_cache, nl_count_buf;
3214 Lisp_Object cache_newlines, buf_newlines, val; 3214 Lisp_Object cache_newlines, buf_newlines, val;
3215 ptrdiff_t from, found, i; 3215 ptrdiff_t from, found, i;
@@ -3220,6 +3220,7 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
3220 { 3220 {
3221 CHECK_BUFFER (buffer); 3221 CHECK_BUFFER (buffer);
3222 buf = XBUFFER (buffer); 3222 buf = XBUFFER (buffer);
3223 old = current_buffer;
3223 } 3224 }
3224 if (buf->base_buffer) 3225 if (buf->base_buffer)
3225 buf = buf->base_buffer; 3226 buf = buf->base_buffer;
@@ -3229,46 +3230,63 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
3229 || buf->newline_cache == NULL) 3230 || buf->newline_cache == NULL)
3230 return Qnil; 3231 return Qnil;
3231 3232
3233 /* find_newline can only work on the current buffer. */
3234 if (old != NULL)
3235 set_buffer_internal_1 (buf);
3236
3232 /* How many newlines are there according to the cache? */ 3237 /* How many newlines are there according to the cache? */
3233 find_newline (BUF_BEG (buf), BUF_BEG_BYTE (buf), 3238 find_newline (BEGV, BEGV_BYTE, ZV, ZV_BYTE,
3234 BUF_Z (buf), BUF_Z_BYTE (buf),
3235 TYPE_MAXIMUM (ptrdiff_t), &shortage, NULL, true); 3239 TYPE_MAXIMUM (ptrdiff_t), &shortage, NULL, true);
3236 nl_count_cache = TYPE_MAXIMUM (ptrdiff_t) - shortage; 3240 nl_count_cache = TYPE_MAXIMUM (ptrdiff_t) - shortage;
3237 3241
3238 /* Create vector and populate it. */ 3242 /* Create vector and populate it. */
3239 cache_newlines = make_uninit_vector (nl_count_cache); 3243 cache_newlines = make_uninit_vector (nl_count_cache);
3240 for (from = BUF_BEG( buf), found = from, i = 0; 3244
3241 from < BUF_Z (buf); 3245 if (nl_count_cache)
3242 from = found, i++)
3243 { 3246 {
3244 ptrdiff_t from_byte = CHAR_TO_BYTE (from); 3247 for (from = BEGV, found = from, i = 0; from < ZV; from = found, i++)
3248 {
3249 ptrdiff_t from_byte = CHAR_TO_BYTE (from);
3245 3250
3246 found = find_newline (from, from_byte, 0, -1, 1, &shortage, NULL, true); 3251 found = find_newline (from, from_byte, 0, -1, 1, &shortage,
3247 if (shortage == 0) 3252 NULL, true);
3248 ASET (cache_newlines, i, make_number (found - 1)); 3253 if (shortage != 0 || i >= nl_count_cache)
3254 break;
3255 ASET (cache_newlines, i, make_number (found - 1));
3256 }
3257 /* Fill the rest of slots with an invalid position. */
3258 for ( ; i < nl_count_cache; i++)
3259 ASET (cache_newlines, i, make_number (-1));
3249 } 3260 }
3250 3261
3251 /* Now do the same, but without using the cache. */ 3262 /* Now do the same, but without using the cache. */
3252 find_newline1 (BUF_BEG (buf), BUF_BEG_BYTE (buf), 3263 find_newline1 (BEGV, BEGV_BYTE, ZV, ZV_BYTE,
3253 BUF_Z (buf), BUF_Z_BYTE (buf),
3254 TYPE_MAXIMUM (ptrdiff_t), &shortage, NULL, true); 3264 TYPE_MAXIMUM (ptrdiff_t), &shortage, NULL, true);
3255 nl_count_buf = TYPE_MAXIMUM (ptrdiff_t) - shortage; 3265 nl_count_buf = TYPE_MAXIMUM (ptrdiff_t) - shortage;
3256 buf_newlines = make_uninit_vector (nl_count_buf); 3266 buf_newlines = make_uninit_vector (nl_count_buf);
3257 for (from = BUF_BEG( buf), found = from, i = 0; 3267 if (nl_count_buf)
3258 from < BUF_Z (buf);
3259 from = found, i++)
3260 { 3268 {
3261 ptrdiff_t from_byte = CHAR_TO_BYTE (from); 3269 for (from = BEGV, found = from, i = 0; from < ZV; from = found, i++)
3270 {
3271 ptrdiff_t from_byte = CHAR_TO_BYTE (from);
3262 3272
3263 found = find_newline1 (from, from_byte, 0, -1, 1, &shortage, NULL, true); 3273 found = find_newline1 (from, from_byte, 0, -1, 1, &shortage,
3264 if (shortage == 0) 3274 NULL, true);
3265 ASET (buf_newlines, i, make_number (found - 1)); 3275 if (shortage != 0 || i >= nl_count_buf)
3276 break;
3277 ASET (buf_newlines, i, make_number (found - 1));
3278 }
3279 for ( ; i < nl_count_buf; i++)
3280 ASET (buf_newlines, i, make_number (-1));
3266 } 3281 }
3267 3282
3268 /* Construct the value and return it. */ 3283 /* Construct the value and return it. */
3269 val = make_uninit_vector (2); 3284 val = make_uninit_vector (2);
3270 ASET (val, 0, cache_newlines); 3285 ASET (val, 0, cache_newlines);
3271 ASET (val, 1, buf_newlines); 3286 ASET (val, 1, buf_newlines);
3287
3288 if (old != NULL)
3289 set_buffer_internal_1 (old);
3272 return val; 3290 return val;
3273} 3291}
3274 3292