emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r100282: Make the cache of bidi itera


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r100282: Make the cache of bidi iterator states dynamically allocated.
Date: Fri, 14 May 2010 18:19:07 +0300
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 100282
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Fri 2010-05-14 18:19:07 +0300
message:
  Make the cache of bidi iterator states dynamically allocated.
  
   bidi.c (bidi_cache_shrink): New function.
   (bidi_init_it): Call it.
   (bidi_cache_iterator_state): Enlarge the cache if needed.
modified:
  src/ChangeLog
  src/bidi.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2010-05-14 14:30:45 +0000
+++ b/src/ChangeLog     2010-05-14 15:19:07 +0000
@@ -1,5 +1,10 @@
 2010-05-14  Eli Zaretskii  <address@hidden>
 
+       Make the cache of bidi iterator states dynamically allocated.
+       (bidi_cache_shrink): New function.
+       (bidi_init_it): Call it.
+       (bidi_cache_iterator_state): Enlarge the cache if needed.
+
        * bidi.c (bidi_move_to_visually_next): Renamed from
        bidi_get_next_char_visually.  All callers changed.
 

=== modified file 'src/bidi.c'
--- a/src/bidi.c        2010-05-14 14:30:45 +0000
+++ b/src/bidi.c        2010-05-14 15:19:07 +0000
@@ -540,9 +540,11 @@
 
 /* Caching the bidi iterator states.  */
 
-static struct bidi_it bidi_cache[1000]; /* FIXME: make this dynamically 
allocated! */
-static int bidi_cache_idx;
-static int bidi_cache_last_idx;
+#define BIDI_CACHE_CHUNK 200
+static struct bidi_it *bidi_cache;
+static size_t bidi_cache_size = 0;
+static int bidi_cache_idx;     /* next unused cache slot */
+static int bidi_cache_last_idx;        /* slot of last cache hit */
 
 static INLINE void
 bidi_cache_reset (void)
@@ -552,6 +554,17 @@
 }
 
 static INLINE void
+bidi_cache_shrink (void)
+{
+  if (bidi_cache_size > BIDI_CACHE_CHUNK)
+    {
+      bidi_cache_size = BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
+      bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
+    }
+  bidi_cache_reset ();
+}
+
+static INLINE void
 bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it)
 {
   int current_scan_dir = bidi_it->scan_dir;
@@ -672,9 +685,13 @@
   if (idx < 0)
     {
       idx = bidi_cache_idx;
-      /* Don't overrun the cache limit.  */
-      if (idx > sizeof (bidi_cache) / sizeof (bidi_cache[0]) - 1)
-       abort ();
+      /* Enlarge the cache as needed.  */
+      if (idx >= bidi_cache_size)
+       {
+         bidi_cache_size += BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
+         bidi_cache =
+           (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
+       }
       /* Character positions should correspond to cache positions 1:1.
         If we are outside the range of cached positions, the cache is
         useless and must be reset.  */
@@ -990,6 +1007,7 @@
     bidi_it->prev_for_neutral.type_after_w1 =
     bidi_it->prev_for_neutral.orig_type = UNKNOWN_BT;
   bidi_it->sor = L2R;   /* FIXME: should it be user-selectable? */
+  bidi_cache_shrink ();
 }
 
 /* Push the current embedding level and override status; reset the


reply via email to

[Prev in Thread] Current Thread [Next in Thread]