Mercurial > hg > xemacs-beta
comparison src/line-number.c @ 5914:bd4d2c8ef9cc
Use the existing C-level line number cache within #'line-number.
src/ChangeLog addition:
2015-05-15 Aidan Kehoe <kehoea@parhasard.net>
* buffer.c:
* buffer.c (Fline_number): New C implementation, using the line
number cache of line-number.c, with a new optional BUFFER
argument.
* buffer.c (syms_of_buffer):
Make it available to Lisp.
* line-number.c (buffer_line_number):
New argument, RESPECT-NARROWING, describing whether to count from
the beginning of the visible region or from the beginning of the
buffer.
* line-number.h:
* line-number.h (buffer_line_number): Update its declaration.
* redisplay.c (window_line_number): Call it with the new argument.
lisp/ChangeLog addition:
2015-05-15 Aidan Kehoe <kehoea@parhasard.net>
* simple.el:
* simple.el (line-number): Moved to buffer.c; we have an existing
line number cache in C, it's a shame not to have it available.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 15 May 2015 18:11:47 +0100 |
parents | 56144c8593a8 |
children |
comparison
equal
deleted
inserted
replaced
5913:1b2fdcc3cc5c | 5914:bd4d2c8ef9cc |
---|---|
264 appropriately. | 264 appropriately. |
265 | 265 |
266 If the calculation (with or without the cache lookup) required more | 266 If the calculation (with or without the cache lookup) required more |
267 than LINE_NUMBER_FAR characters of traversal, update the cache. */ | 267 than LINE_NUMBER_FAR characters of traversal, update the cache. */ |
268 EMACS_INT | 268 EMACS_INT |
269 buffer_line_number (struct buffer *b, Charbpos pos, int cachep) | 269 buffer_line_number (struct buffer *b, Charbpos pos, Boolint cachep, |
270 { | 270 Boolint respect_narrowing) |
271 Charbpos beg = BUF_BEGV (b); | 271 { |
272 Charbpos beg = respect_narrowing ? BUF_BEGV (b) : BUF_BEG (b); | |
272 EMACS_INT cached_lines = 0; | 273 EMACS_INT cached_lines = 0; |
273 EMACS_INT shortage, line; | 274 EMACS_INT shortage, line; |
274 | 275 |
275 if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR) | 276 if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR) |
276 cachep = 0; | 277 cachep = 0; |
277 | 278 |
278 if (cachep) | 279 if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b))) |
279 { | 280 { |
280 if (NILP (b->text->line_number_cache)) | 281 if (NILP (b->text->line_number_cache)) |
281 allocate_line_number_cache (b); | 282 allocate_line_number_cache (b); |
282 /* If we don't know the line number of BUF_BEGV, calculate it now. */ | 283 /* If we don't know the line number of BUF_BEGV, calculate it now. */ |
283 if (XFIXNUM (LINE_NUMBER_BEGV (b)) == -1) | 284 if (XFIXNUM (LINE_NUMBER_BEGV (b)) == -1) |
284 { | 285 { |
285 LINE_NUMBER_BEGV (b) = Qzero; | 286 LINE_NUMBER_BEGV (b) = Qzero; |
286 /* #### This has a side-effect of changing the cache. */ | 287 /* #### This has a side-effect of changing the cache. */ |
287 LINE_NUMBER_BEGV (b) = | 288 LINE_NUMBER_BEGV (b) = |
288 make_fixnum (buffer_line_number (b, BUF_BEGV (b), 1)); | 289 make_fixnum (buffer_line_number (b, BUF_BEGV (b), 1, 0)); |
289 } | 290 } |
290 cached_lines = XFIXNUM (LINE_NUMBER_BEGV (b)); | 291 cached_lines = XFIXNUM (LINE_NUMBER_BEGV (b)); |
291 get_nearest_line_number (b, &beg, pos, &cached_lines); | 292 get_nearest_line_number (b, &beg, pos, &cached_lines); |
292 } | 293 } |
293 | 294 |
294 scan_buffer (b, '\n', beg, pos, pos > beg ? MOST_POSITIVE_FIXNUM : -MOST_POSITIVE_FIXNUM, | 295 scan_buffer (b, '\n', beg, pos, |
296 pos > beg ? MOST_POSITIVE_FIXNUM : -MOST_POSITIVE_FIXNUM, | |
295 &shortage, 0); | 297 &shortage, 0); |
296 | 298 |
297 line = MOST_POSITIVE_FIXNUM - shortage; | 299 line = MOST_POSITIVE_FIXNUM - shortage; |
298 if (beg > pos) | 300 if (beg > pos) |
299 line = -line; | 301 line = -line; |
300 line += cached_lines; | 302 line += cached_lines; |
301 | 303 |
302 if (cachep) | 304 if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b))) |
303 { | 305 { |
304 /* If too far, update the cache. */ | 306 /* If too far, update the cache. */ |
305 if ((pos > beg ? pos - beg : beg - pos) > LINE_NUMBER_FAR) | 307 if ((pos > beg ? pos - beg : beg - pos) > LINE_NUMBER_FAR) |
306 add_position_to_cache (b, pos, line); | 308 add_position_to_cache (b, pos, line); |
307 /* Account for narrowing. If cache is not used, this is | 309 /* Account for narrowing. If cache is not used, this is |