Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/vte/src/Makefile.am,v
retrieving revision 1.73
diff -u -3 -p -r1.73 Makefile.am
--- Makefile.am	30 Apr 2004 01:16:53 -0000	1.73
+++ Makefile.am	18 Aug 2004 18:40:38 -0000
@@ -83,6 +83,8 @@ libvte_la_SOURCES = \
 	vteskel.h \
 	vtetc.c \
 	vtetc.h \
+	vtetree.c \
+	vtetree.h \
 	vtexft.c \
 	vtexft.h
 
Index: vtexft.c
===================================================================
RCS file: /cvs/gnome/vte/src/vtexft.c,v
retrieving revision 1.19
diff -u -3 -p -r1.19 vtexft.c
--- vtexft.c	20 Apr 2004 05:16:56 -0000	1.19
+++ vtexft.c	18 Aug 2004 18:40:48 -0000
@@ -35,6 +35,7 @@
 #include "vtedraw.h"
 #include "vtefc.h"
 #include "vtexft.h"
+#include "vtetree.h"
 
 #ifdef ENABLE_NLS
 #include <libintl.h>
@@ -53,8 +54,8 @@ struct _vte_xft_font {
 #endif
 	GArray *patterns;
 	GArray *fonts;
-	GTree *fontmap;
-	GTree *widths;
+	VteTree *fontmap;
+	VteTree *widths;
 };
 
 struct _vte_xft_data
@@ -124,8 +125,8 @@ _vte_xft_font_open(GtkWidget *widget, co
 #endif
 	font->patterns = patterns;
 	font->fonts = g_array_new(TRUE, TRUE, sizeof(XftFont*));
-	font->fontmap = g_tree_new(_vte_xft_direct_compare);
-	font->widths = g_tree_new(_vte_xft_direct_compare);
+	font->fontmap = _vte_tree_new(_vte_xft_direct_compare);
+	font->widths = _vte_tree_new(_vte_xft_direct_compare);
 
 	return font;
 }
@@ -166,9 +167,9 @@ _vte_xft_font_close(struct _vte_xft_font
 	g_array_free(font->fonts, TRUE);
 	font->fonts = NULL;
 
-	g_tree_destroy(font->fontmap);
+	_vte_tree_destroy(font->fontmap);
 	font->fontmap = NULL;
-	g_tree_destroy(font->widths);
+	_vte_tree_destroy(font->widths);
 	font->widths = NULL;
 
 	g_free(font);
@@ -191,7 +192,7 @@ _vte_xft_font_for_char(struct _vte_xft_f
 	g_return_val_if_fail(font->widths != NULL, NULL);
 
 	/* Check if we have a char-to-font entry for it. */
-	i = GPOINTER_TO_INT(g_tree_lookup(font->fontmap, p));
+	i = GPOINTER_TO_INT(_vte_tree_lookup(font->fontmap, p));
 	if (i != 0) {
 		switch (i) {
 		/* Checked before, no luck. */
@@ -225,7 +226,7 @@ _vte_xft_font_for_char(struct _vte_xft_f
 
 	/* Match? */
 	if (i < font->fonts->len) {
-		g_tree_insert(font->fontmap,
+		_vte_tree_insert(font->fontmap,
 			      p,
 			      GINT_TO_POINTER(i + FONT_INDEX_FUDGE));
 		ftfont = g_array_index(font->fonts, XftFont *, i);
@@ -253,7 +254,7 @@ _vte_xft_font_for_char(struct _vte_xft_f
 
 	/* No match? */
 	if (i >= font->patterns->len) {
-		g_tree_insert(font->fontmap,
+		_vte_tree_insert(font->fontmap,
 			      p,
 			      GINT_TO_POINTER(-FONT_INDEX_FUDGE));
 		if (font->fonts->len > 0) {
@@ -288,7 +289,7 @@ _vte_xft_char_width(struct _vte_xft_font
 	g_return_val_if_fail(font->widths != NULL, 0);
 
 	/* Check if we have a char-to-width entry for it. */
-	i = GPOINTER_TO_INT(g_tree_lookup(font->widths, p));
+	i = GPOINTER_TO_INT(_vte_tree_lookup(font->widths, p));
 	if (i != 0) {
 		switch (i) {
 		case -CHAR_WIDTH_FUDGE:
@@ -306,7 +307,7 @@ _vte_xft_char_width(struct _vte_xft_font
 		_vte_xft_text_extents(font, ftfont, c, &extents);
 	}
 	i = extents.xOff + CHAR_WIDTH_FUDGE;
-	g_tree_insert(font->widths, p, GINT_TO_POINTER(i));
+	_vte_tree_insert(font->widths, p, GINT_TO_POINTER(i));
 	return extents.xOff;
 }
 
--- /dev/null	2004-08-18 13:15:34.000000000 +0200
+++ vtetree.c	2004-08-18 14:00:31.000000000 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
+ *
+ * This is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* The interfaces in this file are subject to change at any time. */
+
+#include "vtetree.h"
+
+VteTree *
+_vte_tree_new(GCompareFunc key_compare_func)
+{
+  VteTree *tree = g_new0 (VteTree, 1);
+  tree->tree = g_tree_new (key_compare_func);
+  return tree;
+}
+
+void 
+_vte_tree_destroy(VteTree *tree)
+{
+  g_tree_destroy (tree->tree);
+  g_free (tree);
+}
+
+void 
+_vte_tree_insert(VteTree *tree, gpointer key, gpointer value)
+{
+  guint index = GPOINTER_TO_UINT (key);
+  
+  if (index < VTE_TREE_ARRAY_SIZE) {
+    tree->array[index] = value;
+    return;
+  }
+  g_tree_insert (tree->tree, key, value);
+}
+
+gpointer
+_vte_tree_lookup(VteTree *tree, gconstpointer key)
+{
+  const guint index = GPOINTER_TO_UINT (key);
+  
+  if (index < VTE_TREE_ARRAY_SIZE)
+    return tree->array[index];
+
+  return g_tree_lookup (tree->tree, key);
+}
+
--- /dev/null	2004-08-18 13:15:34.000000000 +0200
+++ vtetree.h	2004-08-18 13:59:54.000000000 +0200
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
+ *
+ * This is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* The interfaces in this file are subject to change at any time. */
+
+#ifndef vte_tree_h_included
+#define vte_tree_h_included
+
+#ident "$Id: trie.h,v 1.10 2002/12/10 00:08:32 nalin Exp $"
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/* This is an optimiziation for GTrees we use with unicode characters. Since
+ * most characters are in the range [0-128], we store that range in an array
+ * for faster access.
+ * We match the API for GTree here.
+ */
+#define VTE_TREE_ARRAY_SIZE (128)
+
+typedef struct _VteTree VteTree;
+struct _VteTree {
+  GTree *tree;
+  gpointer array[VTE_TREE_ARRAY_SIZE];
+};
+
+VteTree *_vte_tree_new(GCompareFunc key_compare_func);
+void _vte_tree_destroy(VteTree *tree);
+void _vte_tree_insert(VteTree *tree, gpointer key, gpointer value);
+gpointer _vte_tree_lookup(VteTree *tree, gconstpointer key);
+/* extend as needed */
+
+G_END_DECLS
+
+#endif
