aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/bidi.c30
2 files changed, 29 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0f3c5673c2a..14311049a17 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
12010-05-14 Eli Zaretskii <eliz@gnu.org> 12010-05-14 Eli Zaretskii <eliz@gnu.org>
2 2
3 Make the cache of bidi iterator states dynamically allocated.
4 (bidi_cache_shrink): New function.
5 (bidi_init_it): Call it.
6 (bidi_cache_iterator_state): Enlarge the cache if needed.
7
3 * bidi.c (bidi_move_to_visually_next): Renamed from 8 * bidi.c (bidi_move_to_visually_next): Renamed from
4 bidi_get_next_char_visually. All callers changed. 9 bidi_get_next_char_visually. All callers changed.
5 10
diff --git a/src/bidi.c b/src/bidi.c
index 4b44699f7b2..c4cb4c599df 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -540,9 +540,11 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from)
540 540
541/* Caching the bidi iterator states. */ 541/* Caching the bidi iterator states. */
542 542
543static struct bidi_it bidi_cache[1000]; /* FIXME: make this dynamically allocated! */ 543#define BIDI_CACHE_CHUNK 200
544static int bidi_cache_idx; 544static struct bidi_it *bidi_cache;
545static int bidi_cache_last_idx; 545static size_t bidi_cache_size = 0;
546static int bidi_cache_idx; /* next unused cache slot */
547static int bidi_cache_last_idx; /* slot of last cache hit */
546 548
547static INLINE void 549static INLINE void
548bidi_cache_reset (void) 550bidi_cache_reset (void)
@@ -552,6 +554,17 @@ bidi_cache_reset (void)
552} 554}
553 555
554static INLINE void 556static INLINE void
557bidi_cache_shrink (void)
558{
559 if (bidi_cache_size > BIDI_CACHE_CHUNK)
560 {
561 bidi_cache_size = BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
562 bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
563 }
564 bidi_cache_reset ();
565}
566
567static INLINE void
555bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it) 568bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it)
556{ 569{
557 int current_scan_dir = bidi_it->scan_dir; 570 int current_scan_dir = bidi_it->scan_dir;
@@ -672,9 +685,13 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved)
672 if (idx < 0) 685 if (idx < 0)
673 { 686 {
674 idx = bidi_cache_idx; 687 idx = bidi_cache_idx;
675 /* Don't overrun the cache limit. */ 688 /* Enlarge the cache as needed. */
676 if (idx > sizeof (bidi_cache) / sizeof (bidi_cache[0]) - 1) 689 if (idx >= bidi_cache_size)
677 abort (); 690 {
691 bidi_cache_size += BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
692 bidi_cache =
693 (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
694 }
678 /* Character positions should correspond to cache positions 1:1. 695 /* Character positions should correspond to cache positions 1:1.
679 If we are outside the range of cached positions, the cache is 696 If we are outside the range of cached positions, the cache is
680 useless and must be reset. */ 697 useless and must be reset. */
@@ -990,6 +1007,7 @@ bidi_init_it (EMACS_INT charpos, EMACS_INT bytepos, struct bidi_it *bidi_it)
990 bidi_it->prev_for_neutral.type_after_w1 = 1007 bidi_it->prev_for_neutral.type_after_w1 =
991 bidi_it->prev_for_neutral.orig_type = UNKNOWN_BT; 1008 bidi_it->prev_for_neutral.orig_type = UNKNOWN_BT;
992 bidi_it->sor = L2R; /* FIXME: should it be user-selectable? */ 1009 bidi_it->sor = L2R; /* FIXME: should it be user-selectable? */
1010 bidi_cache_shrink ();
993} 1011}
994 1012
995/* Push the current embedding level and override status; reset the 1013/* Push the current embedding level and override status; reset the