#include "gtktextiterprivate.h"
#include "gtktextlinedisplaycacheprivate.h"
-#define MRU_MAX_SIZE 250
+#define DEFAULT_MRU_SIZE 250
#define BLOW_CACHE_TIMEOUT_SEC 20
#define DEBUG_LINE_DISPLAY_CACHE 0
GtkTextLine *cursor_line;
GQueue mru;
GSource *evict_source;
+ guint mru_size;
#if DEBUG_LINE_DISPLAY_CACHE
guint log_source;
ret = g_slice_new0 (GtkTextLineDisplayCache);
ret->sorted_by_line = g_sequence_new ((GDestroyNotify)gtk_text_line_display_unref);
ret->line_to_display = g_hash_table_new (NULL, NULL);
+ ret->mru_size = DEFAULT_MRU_SIZE;
#if DEBUG_LINE_DISPLAY_CACHE
ret->log_source = g_timeout_add_seconds (1, dump_stats, ret);
g_queue_push_head_link (&cache->mru, &display->mru_link);
/* Cull the cache if we're at capacity */
- while (cache->mru.length > MRU_MAX_SIZE)
+ while (cache->mru.length > cache->mru_size)
{
display = g_queue_peek_tail (&cache->mru);
if (display != NULL)
gtk_text_line_display_cache_invalidate_display (cache, display, FALSE);
}
+
+void
+gtk_text_line_display_cache_set_mru_size (GtkTextLineDisplayCache *cache,
+ guint mru_size)
+{
+ GtkTextLineDisplay *display;
+
+ g_assert (cache != NULL);
+
+ if (mru_size == 0)
+ mru_size = DEFAULT_MRU_SIZE;
+
+ if (mru_size != cache->mru_size)
+ {
+ cache->mru_size = mru_size;
+
+ while (cache->mru.length > cache->mru_size)
+ {
+ display = g_queue_peek_tail (&cache->mru);
+
+ gtk_text_line_display_cache_invalidate_display (cache, display, FALSE);
+ }
+ }
+}
GdkRectangle top_rect;
GdkRectangle bottom_rect;
GtkWidget *chooser;
+ PangoLayout *layout;
+ guint mru_size;
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
if (!gtk_adjustment_is_animating (priv->vadjustment))
gtk_text_view_set_vadjustment_values (text_view);
+ /* Optimize display cache size */
+ layout = gtk_widget_create_pango_layout (widget, "X");
+ pango_layout_get_pixel_size (layout, &width, &height);
+ if (height > 0)
+ {
+ mru_size = SCREEN_HEIGHT (widget) / height * 3;
+ gtk_text_layout_set_mru_size (priv->layout, mru_size);
+ }
+ g_object_unref (layout);
+
/* The GTK resize loop processes all the pending exposes right
* after doing the resize stuff, so the idle sizer won't have a
* chance to run. So we do the work here.