Mercurial > emacs
comparison src/region-cache.c @ 110507:875202ac5b45
Fix use of int instead of EMACS_INT in search.c and region-cache.c.
indent.c (compute_motion): Use EMACS_INT for arguments to
region_cache_forward.
region-cache.c (struct boundary, struct region_cache): Use
EMACS_INT for positions.
(find_cache_boundary, move_cache_gap, insert_cache_boundary)
(delete_cache_boundaries, set_cache_region)
(invalidate_region_cache, know_region_cache)
(region_cache_forward, region_cache_backward, pp_cache): Use
EMACS_INT for buffer positions.
region-cache.h (know_region_cache, invalidate_region_cache)
(region_cache_forward, region_cache_backward): Adjust prototypes.
search.c (string_match_1, fast_c_string_match_ignore_case)
(looking_at_1, scan_buffer, scan_newline)
(find_next_newline_no_quit, find_before_next_newline)
(search_command, trivial_regexp_p, search_buffer, simple_search)
(boyer_moore, wordify, Freplace_match): Use EMACS_INT for buffer
and string positions and length.
lisp.h (scan_buffer, scan_newline, find_next_newline_no_quit)
(find_before_next_newline): Adjust prototypes.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 23 Sep 2010 14:35:11 -0400 |
parents | aec1143e8d85 |
children | f3ee3c073b92 |
comparison
equal
deleted
inserted
replaced
110506:2cac83f5f8bc | 110507:875202ac5b45 |
---|---|
60 positions after the gap are stored relative to BUF_Z (buf) (thus | 60 positions after the gap are stored relative to BUF_Z (buf) (thus |
61 they're <= 0). Look at BOUNDARY_POS to see this in action. See | 61 they're <= 0). Look at BOUNDARY_POS to see this in action. See |
62 revalidate_region_cache to see how this helps. */ | 62 revalidate_region_cache to see how this helps. */ |
63 | 63 |
64 struct boundary { | 64 struct boundary { |
65 int pos; | 65 EMACS_INT pos; |
66 int value; | 66 int value; |
67 }; | 67 }; |
68 | 68 |
69 struct region_cache { | 69 struct region_cache { |
70 /* A sorted array of locations where the known-ness of the buffer | 70 /* A sorted array of locations where the known-ness of the buffer |
71 changes. */ | 71 changes. */ |
72 struct boundary *boundaries; | 72 struct boundary *boundaries; |
73 | 73 |
74 /* boundaries[gap_start ... gap_start + gap_len - 1] is the gap. */ | 74 /* boundaries[gap_start ... gap_start + gap_len - 1] is the gap. */ |
75 int gap_start, gap_len; | 75 EMACS_INT gap_start, gap_len; |
76 | 76 |
77 /* The number of elements allocated to boundaries, not including the | 77 /* The number of elements allocated to boundaries, not including the |
78 gap. */ | 78 gap. */ |
79 int cache_len; | 79 int cache_len; |
80 | 80 |
81 /* The areas that haven't changed since the last time we cleaned out | 81 /* The areas that haven't changed since the last time we cleaned out |
82 invalid entries from the cache. These overlap when the buffer is | 82 invalid entries from the cache. These overlap when the buffer is |
83 entirely unchanged. */ | 83 entirely unchanged. */ |
84 int beg_unchanged, end_unchanged; | 84 EMACS_INT beg_unchanged, end_unchanged; |
85 | 85 |
86 /* The first and last positions in the buffer. Because boundaries | 86 /* The first and last positions in the buffer. Because boundaries |
87 store their positions relative to the start (BEG) and end (Z) of | 87 store their positions relative to the start (BEG) and end (Z) of |
88 the buffer, knowing these positions allows us to accurately | 88 the buffer, knowing these positions allows us to accurately |
89 interpret positions without having to pass the buffer structure | 89 interpret positions without having to pass the buffer structure |
90 or its endpoints around all the time. | 90 or its endpoints around all the time. |
91 | 91 |
92 Yes, buffer_beg is always 1. It's there for symmetry with | 92 Yes, buffer_beg is always 1. It's there for symmetry with |
93 buffer_end and the BEG and BUF_BEG macros. */ | 93 buffer_end and the BEG and BUF_BEG macros. */ |
94 int buffer_beg, buffer_end; | 94 EMACS_INT buffer_beg, buffer_end; |
95 }; | 95 }; |
96 | 96 |
97 /* Return the position of boundary i in cache c. */ | 97 /* Return the position of boundary i in cache c. */ |
98 #define BOUNDARY_POS(c, i) \ | 98 #define BOUNDARY_POS(c, i) \ |
99 ((i) < (c)->gap_start \ | 99 ((i) < (c)->gap_start \ |
171 | 171 |
172 This operation should be logarithmic in the number of cache | 172 This operation should be logarithmic in the number of cache |
173 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 |
174 reference, too, by searching entries near the last entry found. */ | 174 reference, too, by searching entries near the last entry found. */ |
175 static int | 175 static int |
176 find_cache_boundary (struct region_cache *c, int pos) | 176 find_cache_boundary (struct region_cache *c, EMACS_INT pos) |
177 { | 177 { |
178 int low = 0, high = c->cache_len; | 178 int low = 0, high = c->cache_len; |
179 | 179 |
180 while (low + 1 < high) | 180 while (low + 1 < high) |
181 { | 181 { |
182 /* mid is always a valid index, because low < high and ">> 1" | 182 /* mid is always a valid index, because low < high and ">> 1" |
183 rounds down. */ | 183 rounds down. */ |
184 int mid = (low + high) >> 1; | 184 int mid = (low + high) >> 1; |
185 int boundary = BOUNDARY_POS (c, mid); | 185 EMACS_INT boundary = BOUNDARY_POS (c, mid); |
186 | 186 |
187 if (pos < boundary) | 187 if (pos < boundary) |
188 high = mid; | 188 high = mid; |
189 else | 189 else |
190 low = mid; | 190 low = mid; |
205 | 205 |
206 | 206 |
207 /* 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 |
208 for at least MIN_SIZE boundaries. */ | 208 for at least MIN_SIZE boundaries. */ |
209 static void | 209 static void |
210 move_cache_gap (struct region_cache *c, int pos, int min_size) | 210 move_cache_gap (struct region_cache *c, EMACS_INT pos, int min_size) |
211 { | 211 { |
212 /* Copy these out of the cache and into registers. */ | 212 /* Copy these out of the cache and into registers. */ |
213 int gap_start = c->gap_start; | 213 EMACS_INT gap_start = c->gap_start; |
214 int gap_len = c->gap_len; | 214 EMACS_INT gap_len = c->gap_len; |
215 int buffer_beg = c->buffer_beg; | 215 EMACS_INT buffer_beg = c->buffer_beg; |
216 int buffer_end = c->buffer_end; | 216 EMACS_INT buffer_end = c->buffer_end; |
217 | 217 |
218 if (pos < 0 | 218 if (pos < 0 |
219 || pos > c->cache_len) | 219 || pos > c->cache_len) |
220 abort (); | 220 abort (); |
221 | 221 |
243 is proportional to the amount of stuff after the gap, we do the | 243 is proportional to the amount of stuff after the gap, we do the |
244 enlargement here, after a right shift but before a left shift, | 244 enlargement here, after a right shift but before a left shift, |
245 when the portion after the gap is smallest. */ | 245 when the portion after the gap is smallest. */ |
246 if (gap_len < min_size) | 246 if (gap_len < min_size) |
247 { | 247 { |
248 int i; | 248 EMACS_INT i; |
249 | 249 |
250 /* Always make at least NEW_CACHE_GAP elements, as long as we're | 250 /* Always make at least NEW_CACHE_GAP elements, as long as we're |
251 expanding anyway. */ | 251 expanding anyway. */ |
252 if (min_size < NEW_CACHE_GAP) | 252 if (min_size < NEW_CACHE_GAP) |
253 min_size = NEW_CACHE_GAP; | 253 min_size = NEW_CACHE_GAP; |
290 | 290 |
291 | 291 |
292 /* 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, |
293 and have the specified POS and VALUE. */ | 293 and have the specified POS and VALUE. */ |
294 static void | 294 static void |
295 insert_cache_boundary (struct region_cache *c, int index, int pos, int value) | 295 insert_cache_boundary (struct region_cache *c, int index, EMACS_INT pos, |
296 int value) | |
296 { | 297 { |
297 /* index must be a valid cache index. */ | 298 /* index must be a valid cache index. */ |
298 if (index < 0 || index > c->cache_len) | 299 if (index < 0 || index > c->cache_len) |
299 abort (); | 300 abort (); |
300 | 301 |
326 | 327 |
327 | 328 |
328 /* Delete the i'th entry from cache C if START <= i < END. */ | 329 /* Delete the i'th entry from cache C if START <= i < END. */ |
329 | 330 |
330 static void | 331 static void |
331 delete_cache_boundaries (struct region_cache *c, int start, int end) | 332 delete_cache_boundaries (struct region_cache *c, |
332 { | 333 EMACS_INT start, EMACS_INT end) |
333 int len = end - start; | 334 { |
335 EMACS_INT len = end - start; | |
334 | 336 |
335 /* Gotta be in range. */ | 337 /* Gotta be in range. */ |
336 if (start < 0 | 338 if (start < 0 |
337 || end > c->cache_len) | 339 || end > c->cache_len) |
338 abort (); | 340 abort (); |
378 | 380 |
379 /* Set the value for a region. */ | 381 /* Set the value for a region. */ |
380 | 382 |
381 /* Set the value in cache C for the region START..END to VALUE. */ | 383 /* Set the value in cache C for the region START..END to VALUE. */ |
382 static void | 384 static void |
383 set_cache_region (struct region_cache *c, int start, int end, int value) | 385 set_cache_region (struct region_cache *c, |
386 EMACS_INT start, EMACS_INT end, int value) | |
384 { | 387 { |
385 if (start > end) | 388 if (start > end) |
386 abort (); | 389 abort (); |
387 if (start < c->buffer_beg | 390 if (start < c->buffer_beg |
388 || end > c->buffer_end) | 391 || end > c->buffer_end) |
479 region. | 482 region. |
480 (This way of specifying regions makes more sense than absolute | 483 (This way of specifying regions makes more sense than absolute |
481 buffer positions in the presence of insertions and deletions; the | 484 buffer positions in the presence of insertions and deletions; the |
482 args to pass are the same before and after such an operation.) */ | 485 args to pass are the same before and after such an operation.) */ |
483 void | 486 void |
484 invalidate_region_cache (struct buffer *buf, struct region_cache *c, int head, int tail) | 487 invalidate_region_cache (struct buffer *buf, struct region_cache *c, |
488 EMACS_INT head, EMACS_INT tail) | |
485 { | 489 { |
486 /* Let chead = c->beg_unchanged, and | 490 /* Let chead = c->beg_unchanged, and |
487 ctail = c->end_unchanged. | 491 ctail = c->end_unchanged. |
488 If z-tail < beg+chead by a large amount, or | 492 If z-tail < beg+chead by a large amount, or |
489 z-ctail < beg+head by a large amount, | 493 z-ctail < beg+head by a large amount, |
685 | 689 |
686 /* Assert that the region of BUF between START and END (absolute | 690 /* Assert that the region of BUF between START and END (absolute |
687 buffer positions) is "known," for the purposes of CACHE (e.g. "has | 691 buffer positions) is "known," for the purposes of CACHE (e.g. "has |
688 no newlines", in the case of the line cache). */ | 692 no newlines", in the case of the line cache). */ |
689 void | 693 void |
690 know_region_cache (struct buffer *buf, struct region_cache *c, int start, int end) | 694 know_region_cache (struct buffer *buf, struct region_cache *c, |
695 EMACS_INT start, EMACS_INT end) | |
691 { | 696 { |
692 revalidate_region_cache (buf, c); | 697 revalidate_region_cache (buf, c); |
693 | 698 |
694 set_cache_region (c, start, end, 1); | 699 set_cache_region (c, start, end, 1); |
695 } | 700 } |
699 | 704 |
700 /* Return true if the text immediately after POS in BUF is known, for | 705 /* Return true if the text immediately after POS in BUF is known, for |
701 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest | 706 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest |
702 position after POS where the knownness changes. */ | 707 position after POS where the knownness changes. */ |
703 int | 708 int |
704 region_cache_forward (struct buffer *buf, struct region_cache *c, int pos, int *next) | 709 region_cache_forward (struct buffer *buf, struct region_cache *c, |
710 EMACS_INT pos, EMACS_INT *next) | |
705 { | 711 { |
706 revalidate_region_cache (buf, c); | 712 revalidate_region_cache (buf, c); |
707 | 713 |
708 { | 714 { |
709 int i = find_cache_boundary (c, pos); | 715 int i = find_cache_boundary (c, pos); |
734 } | 740 } |
735 | 741 |
736 /* Return true if the text immediately before POS in BUF is known, for | 742 /* Return true if the text immediately before POS in BUF is known, for |
737 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest | 743 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest |
738 position before POS where the knownness changes. */ | 744 position before POS where the knownness changes. */ |
739 int region_cache_backward (struct buffer *buf, struct region_cache *c, int pos, int *next) | 745 int region_cache_backward (struct buffer *buf, struct region_cache *c, |
746 EMACS_INT pos, EMACS_INT *next) | |
740 { | 747 { |
741 revalidate_region_cache (buf, c); | 748 revalidate_region_cache (buf, c); |
742 | 749 |
743 /* Before the beginning of the buffer is unknown, by | 750 /* Before the beginning of the buffer is unknown, by |
744 definition. */ | 751 definition. */ |
775 | 782 |
776 void | 783 void |
777 pp_cache (struct region_cache *c) | 784 pp_cache (struct region_cache *c) |
778 { | 785 { |
779 int i; | 786 int i; |
780 int beg_u = c->buffer_beg + c->beg_unchanged; | 787 EMACS_INT beg_u = c->buffer_beg + c->beg_unchanged; |
781 int end_u = c->buffer_end - c->end_unchanged; | 788 EMACS_INT end_u = c->buffer_end - c->end_unchanged; |
782 | 789 |
783 fprintf (stderr, | 790 fprintf (stderr, |
784 "basis: %d..%d modified: %d..%d\n", | 791 "basis: %d..%d modified: %d..%d\n", |
785 c->buffer_beg, c->buffer_end, | 792 c->buffer_beg, c->buffer_end, |
786 beg_u, end_u); | 793 beg_u, end_u); |