Mercurial > emacs
comparison src/region-cache.c @ 109126:aec1143e8d85
Convert (most) functions in src to standard C.
* src/alloc.c: Convert function definitions to standard C.
* src/atimer.c:
* src/bidi.c:
* src/bytecode.c:
* src/callint.c:
* src/callproc.c:
* src/casefiddle.c:
* src/casetab.c:
* src/category.c:
* src/ccl.c:
* src/character.c:
* src/charset.c:
* src/chartab.c:
* src/cmds.c:
* src/coding.c:
* src/composite.c:
* src/data.c:
* src/dbusbind.c:
* src/dired.c:
* src/dispnew.c:
* src/doc.c:
* src/doprnt.c:
* src/ecrt0.c:
* src/editfns.c:
* src/fileio.c:
* src/filelock.c:
* src/filemode.c:
* src/fns.c:
* src/font.c:
* src/fontset.c:
* src/frame.c:
* src/fringe.c:
* src/ftfont.c:
* src/ftxfont.c:
* src/gtkutil.c:
* src/indent.c:
* src/insdel.c:
* src/intervals.c:
* src/keymap.c:
* src/lread.c:
* src/macros.c:
* src/marker.c:
* src/md5.c:
* src/menu.c:
* src/minibuf.c:
* src/prefix-args.c:
* src/print.c:
* src/ralloc.c:
* src/regex.c:
* src/region-cache.c:
* src/scroll.c:
* src/search.c:
* src/sound.c:
* src/strftime.c:
* src/syntax.c:
* src/sysdep.c:
* src/termcap.c:
* src/terminal.c:
* src/terminfo.c:
* src/textprop.c:
* src/tparam.c:
* src/undo.c:
* src/unexelf.c:
* src/window.c:
* src/xfaces.c:
* src/xfns.c:
* src/xfont.c:
* src/xftfont.c:
* src/xgselect.c:
* src/xmenu.c:
* src/xrdb.c:
* src/xselect.c:
* src/xsettings.c:
* src/xsmfns.c:
* src/xterm.c: Likewise.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sun, 04 Jul 2010 00:50:25 -0700 |
parents | 1d1d5d9bd884 |
children | 875202ac5b45 |
comparison
equal
deleted
inserted
replaced
109125:12b02558bf51 | 109126:aec1143e8d85 |
---|---|
120 information about this many characters, call | 120 information about this many characters, call |
121 revalidate_region_cache before doing the new invalidation, to | 121 revalidate_region_cache before doing the new invalidation, to |
122 preserve that information, instead of throwing it away. */ | 122 preserve that information, instead of throwing it away. */ |
123 #define PRESERVE_THRESHOLD (500) | 123 #define PRESERVE_THRESHOLD (500) |
124 | 124 |
125 static void revalidate_region_cache (); | 125 static void revalidate_region_cache (struct buffer *buf, struct region_cache *c); |
126 | 126 |
127 | 127 |
128 /* Interface: Allocating, initializing, and disposing of region caches. */ | 128 /* Interface: Allocating, initializing, and disposing of region caches. */ |
129 | 129 |
130 struct region_cache * | 130 struct region_cache * |
131 new_region_cache () | 131 new_region_cache (void) |
132 { | 132 { |
133 struct region_cache *c | 133 struct region_cache *c |
134 = (struct region_cache *) xmalloc (sizeof (struct region_cache)); | 134 = (struct region_cache *) xmalloc (sizeof (struct region_cache)); |
135 | 135 |
136 c->gap_start = 0; | 136 c->gap_start = 0; |
154 | 154 |
155 return c; | 155 return c; |
156 } | 156 } |
157 | 157 |
158 void | 158 void |
159 free_region_cache (c) | 159 free_region_cache (struct region_cache *c) |
160 struct region_cache *c; | |
161 { | 160 { |
162 xfree (c->boundaries); | 161 xfree (c->boundaries); |
163 xfree (c); | 162 xfree (c); |
164 } | 163 } |
165 | 164 |
172 | 171 |
173 This operation should be logarithmic in the number of cache | 172 This operation should be logarithmic in the number of cache |
174 entries. It would be nice if it took advantage of locality of | 173 entries. It would be nice if it took advantage of locality of |
175 reference, too, by searching entries near the last entry found. */ | 174 reference, too, by searching entries near the last entry found. */ |
176 static int | 175 static int |
177 find_cache_boundary (c, pos) | 176 find_cache_boundary (struct region_cache *c, int pos) |
178 struct region_cache *c; | |
179 int pos; | |
180 { | 177 { |
181 int low = 0, high = c->cache_len; | 178 int low = 0, high = c->cache_len; |
182 | 179 |
183 while (low + 1 < high) | 180 while (low + 1 < high) |
184 { | 181 { |
208 | 205 |
209 | 206 |
210 /* Move the gap of cache C to index POS, and make sure it has space | 207 /* Move the gap of cache C to index POS, and make sure it has space |
211 for at least MIN_SIZE boundaries. */ | 208 for at least MIN_SIZE boundaries. */ |
212 static void | 209 static void |
213 move_cache_gap (c, pos, min_size) | 210 move_cache_gap (struct region_cache *c, int pos, int min_size) |
214 struct region_cache *c; | |
215 int pos; | |
216 int min_size; | |
217 { | 211 { |
218 /* Copy these out of the cache and into registers. */ | 212 /* Copy these out of the cache and into registers. */ |
219 int gap_start = c->gap_start; | 213 int gap_start = c->gap_start; |
220 int gap_len = c->gap_len; | 214 int gap_len = c->gap_len; |
221 int buffer_beg = c->buffer_beg; | 215 int buffer_beg = c->buffer_beg; |
296 | 290 |
297 | 291 |
298 /* Insert a new boundary in cache C; it will have cache index INDEX, | 292 /* Insert a new boundary in cache C; it will have cache index INDEX, |
299 and have the specified POS and VALUE. */ | 293 and have the specified POS and VALUE. */ |
300 static void | 294 static void |
301 insert_cache_boundary (c, index, pos, value) | 295 insert_cache_boundary (struct region_cache *c, int index, int pos, int value) |
302 struct region_cache *c; | |
303 int index; | |
304 int pos, value; | |
305 { | 296 { |
306 /* index must be a valid cache index. */ | 297 /* index must be a valid cache index. */ |
307 if (index < 0 || index > c->cache_len) | 298 if (index < 0 || index > c->cache_len) |
308 abort (); | 299 abort (); |
309 | 300 |
335 | 326 |
336 | 327 |
337 /* Delete the i'th entry from cache C if START <= i < END. */ | 328 /* Delete the i'th entry from cache C if START <= i < END. */ |
338 | 329 |
339 static void | 330 static void |
340 delete_cache_boundaries (c, start, end) | 331 delete_cache_boundaries (struct region_cache *c, int start, int end) |
341 struct region_cache *c; | |
342 int start, end; | |
343 { | 332 { |
344 int len = end - start; | 333 int len = end - start; |
345 | 334 |
346 /* Gotta be in range. */ | 335 /* Gotta be in range. */ |
347 if (start < 0 | 336 if (start < 0 |
389 | 378 |
390 /* Set the value for a region. */ | 379 /* Set the value for a region. */ |
391 | 380 |
392 /* Set the value in cache C for the region START..END to VALUE. */ | 381 /* Set the value in cache C for the region START..END to VALUE. */ |
393 static void | 382 static void |
394 set_cache_region (c, start, end, value) | 383 set_cache_region (struct region_cache *c, int start, int end, int value) |
395 struct region_cache *c; | |
396 int start, end; | |
397 int value; | |
398 { | 384 { |
399 if (start > end) | 385 if (start > end) |
400 abort (); | 386 abort (); |
401 if (start < c->buffer_beg | 387 if (start < c->buffer_beg |
402 || end > c->buffer_end) | 388 || end > c->buffer_end) |
493 region. | 479 region. |
494 (This way of specifying regions makes more sense than absolute | 480 (This way of specifying regions makes more sense than absolute |
495 buffer positions in the presence of insertions and deletions; the | 481 buffer positions in the presence of insertions and deletions; the |
496 args to pass are the same before and after such an operation.) */ | 482 args to pass are the same before and after such an operation.) */ |
497 void | 483 void |
498 invalidate_region_cache (buf, c, head, tail) | 484 invalidate_region_cache (struct buffer *buf, struct region_cache *c, int head, int tail) |
499 struct buffer *buf; | |
500 struct region_cache *c; | |
501 int head, tail; | |
502 { | 485 { |
503 /* Let chead = c->beg_unchanged, and | 486 /* Let chead = c->beg_unchanged, and |
504 ctail = c->end_unchanged. | 487 ctail = c->end_unchanged. |
505 If z-tail < beg+chead by a large amount, or | 488 If z-tail < beg+chead by a large amount, or |
506 z-ctail < beg+head by a large amount, | 489 z-ctail < beg+head by a large amount, |
574 | 557 |
575 Calling this function may be expensive; it does binary searches in | 558 Calling this function may be expensive; it does binary searches in |
576 the cache, and causes cache gap motion. */ | 559 the cache, and causes cache gap motion. */ |
577 | 560 |
578 static void | 561 static void |
579 revalidate_region_cache (buf, c) | 562 revalidate_region_cache (struct buffer *buf, struct region_cache *c) |
580 struct buffer *buf; | |
581 struct region_cache *c; | |
582 { | 563 { |
583 /* The boundaries now in the cache are expressed relative to the | 564 /* The boundaries now in the cache are expressed relative to the |
584 buffer_beg and buffer_end values stored in the cache. Now, | 565 buffer_beg and buffer_end values stored in the cache. Now, |
585 buffer_beg and buffer_end may not be the same as BUF_BEG (buf) | 566 buffer_beg and buffer_end may not be the same as BUF_BEG (buf) |
586 and BUF_Z (buf), so we have two different "bases" to deal with | 567 and BUF_Z (buf), so we have two different "bases" to deal with |
704 | 685 |
705 /* Assert that the region of BUF between START and END (absolute | 686 /* Assert that the region of BUF between START and END (absolute |
706 buffer positions) is "known," for the purposes of CACHE (e.g. "has | 687 buffer positions) is "known," for the purposes of CACHE (e.g. "has |
707 no newlines", in the case of the line cache). */ | 688 no newlines", in the case of the line cache). */ |
708 void | 689 void |
709 know_region_cache (buf, c, start, end) | 690 know_region_cache (struct buffer *buf, struct region_cache *c, int start, int end) |
710 struct buffer *buf; | |
711 struct region_cache *c; | |
712 int start, end; | |
713 { | 691 { |
714 revalidate_region_cache (buf, c); | 692 revalidate_region_cache (buf, c); |
715 | 693 |
716 set_cache_region (c, start, end, 1); | 694 set_cache_region (c, start, end, 1); |
717 } | 695 } |
721 | 699 |
722 /* Return true if the text immediately after POS in BUF is known, for | 700 /* Return true if the text immediately after POS in BUF is known, for |
723 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest | 701 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest |
724 position after POS where the knownness changes. */ | 702 position after POS where the knownness changes. */ |
725 int | 703 int |
726 region_cache_forward (buf, c, pos, next) | 704 region_cache_forward (struct buffer *buf, struct region_cache *c, int pos, int *next) |
727 struct buffer *buf; | |
728 struct region_cache *c; | |
729 int pos; | |
730 int *next; | |
731 { | 705 { |
732 revalidate_region_cache (buf, c); | 706 revalidate_region_cache (buf, c); |
733 | 707 |
734 { | 708 { |
735 int i = find_cache_boundary (c, pos); | 709 int i = find_cache_boundary (c, pos); |
760 } | 734 } |
761 | 735 |
762 /* Return true if the text immediately before POS in BUF is known, for | 736 /* Return true if the text immediately before POS in BUF is known, for |
763 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest | 737 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest |
764 position before POS where the knownness changes. */ | 738 position before POS where the knownness changes. */ |
765 int region_cache_backward (buf, c, pos, next) | 739 int region_cache_backward (struct buffer *buf, struct region_cache *c, int pos, int *next) |
766 struct buffer *buf; | |
767 struct region_cache *c; | |
768 int pos; | |
769 int *next; | |
770 { | 740 { |
771 revalidate_region_cache (buf, c); | 741 revalidate_region_cache (buf, c); |
772 | 742 |
773 /* Before the beginning of the buffer is unknown, by | 743 /* Before the beginning of the buffer is unknown, by |
774 definition. */ | 744 definition. */ |
802 | 772 |
803 | 773 |
804 /* Debugging: pretty-print a cache to the standard error output. */ | 774 /* Debugging: pretty-print a cache to the standard error output. */ |
805 | 775 |
806 void | 776 void |
807 pp_cache (c) | 777 pp_cache (struct region_cache *c) |
808 struct region_cache *c; | |
809 { | 778 { |
810 int i; | 779 int i; |
811 int beg_u = c->buffer_beg + c->beg_unchanged; | 780 int beg_u = c->buffer_beg + c->beg_unchanged; |
812 int end_u = c->buffer_end - c->end_unchanged; | 781 int end_u = c->buffer_end - c->end_unchanged; |
813 | 782 |