Mercurial > pidgin
comparison src/gtkimhtml.c @ 2349:60c716c32c40
[gaim-migrate @ 2362]
(Names changed to protect the innocent.)
blue:~/gaim/app/src $ ls -l ~/.gaim/logs/mid.log
-rw-r--r-- 1 eric eric 607043 Sep 20 03:28 /home/eric/.gaim/logs/mid.log
Previously on my 1.4GHz Athlon, displaying this 600k log file in the Log Viewer took 42 seconds:
time start: 1001157353
time end : 1001157395
Now, with the new smiley checker, it takes 23:
time start: 1001157199
time end : 1001157222
That's still horrible, but it's only a little more than half the time it previously took.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 22 Sep 2001 11:22:59 +0000 |
parents | dd5f18429dd9 |
children | 08c66712364c |
comparison
equal
deleted
inserted
replaced
2348:dd5f18429dd9 | 2349:60c716c32c40 |
---|---|
70 | 70 |
71 #define DRAW_IMG(x) (((x)->type == TYPE_IMG) || (imhtml->smileys && ((x)->type == TYPE_SMILEY))) | 71 #define DRAW_IMG(x) (((x)->type == TYPE_IMG) || (imhtml->smileys && ((x)->type == TYPE_SMILEY))) |
72 | 72 |
73 typedef struct _GtkIMHtmlBit GtkIMHtmlBit; | 73 typedef struct _GtkIMHtmlBit GtkIMHtmlBit; |
74 typedef struct _FontDetail FontDetail; | 74 typedef struct _FontDetail FontDetail; |
75 | |
76 struct _GtkSmileyTree { | |
77 GString *values; | |
78 GtkSmileyTree **children; | |
79 gchar **image; | |
80 }; | |
81 | |
82 static GtkSmileyTree* | |
83 gtk_smiley_tree_new () | |
84 { | |
85 return g_new0 (GtkSmileyTree, 1); | |
86 } | |
87 | |
88 static void | |
89 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
90 const gchar *text, | |
91 gchar **image) | |
92 { | |
93 GtkSmileyTree *t = tree; | |
94 const gchar *x = text; | |
95 | |
96 if (!strlen (x)) | |
97 return; | |
98 | |
99 while (*x) { | |
100 gchar *pos; | |
101 gint index; | |
102 | |
103 if (!t->values) | |
104 t->values = g_string_new (""); | |
105 | |
106 pos = strchr (t->values->str, *x); | |
107 if (!pos) { | |
108 t->values = g_string_append_c (t->values, *x); | |
109 index = t->values->len - 1; | |
110 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
111 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
112 } else | |
113 index = (int) pos - (int) t->values->str; | |
114 | |
115 t = t->children [index]; | |
116 | |
117 x++; | |
118 } | |
119 | |
120 t->image = image; | |
121 } | |
122 | |
123 static void | |
124 gtk_smiley_tree_remove (GtkSmileyTree *tree, | |
125 const gchar *text) | |
126 { | |
127 GtkSmileyTree *t = tree; | |
128 const gchar *x = text; | |
129 gint len = 0; | |
130 | |
131 while (*x) { | |
132 gchar *pos; | |
133 | |
134 if (t->image) { | |
135 t->image = NULL; | |
136 return; | |
137 } | |
138 | |
139 if (!t->values) | |
140 return; | |
141 | |
142 pos = strchr (t->values->str, *x); | |
143 if (pos) | |
144 t = t->children [(int) pos - (int) t->values->str]; | |
145 else | |
146 return; | |
147 | |
148 x++; len++; | |
149 } | |
150 | |
151 if (t->image) | |
152 t->image = NULL; | |
153 } | |
154 | |
155 static gint | |
156 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
157 const gchar *text) | |
158 { | |
159 GtkSmileyTree *t = tree; | |
160 const gchar *x = text; | |
161 gint len = 0; | |
162 | |
163 while (*x) { | |
164 gchar *pos; | |
165 | |
166 if (t->image) | |
167 return len; | |
168 | |
169 if (!t->values) | |
170 return 0; | |
171 | |
172 pos = strchr (t->values->str, *x); | |
173 if (pos) | |
174 t = t->children [(int) pos - (int) t->values->str]; | |
175 else | |
176 return 0; | |
177 | |
178 x++; len++; | |
179 } | |
180 | |
181 if (t->image) | |
182 return len; | |
183 | |
184 return 0; | |
185 } | |
186 | |
187 static gchar** | |
188 gtk_smiley_tree_image (GtkSmileyTree *tree, | |
189 const gchar *text) | |
190 { | |
191 GtkSmileyTree *t = tree; | |
192 const gchar *x = text; | |
193 | |
194 while (*x) { | |
195 gchar *pos; | |
196 | |
197 if (!t->values) | |
198 return NULL; | |
199 | |
200 pos = strchr (t->values->str, *x); | |
201 if (pos) { | |
202 t = t->children [(int) pos - (int) t->values->str]; | |
203 } else | |
204 return NULL; | |
205 | |
206 x++; | |
207 } | |
208 | |
209 return t->image; | |
210 } | |
211 | |
212 static void | |
213 gtk_smiley_tree_destroy (GtkSmileyTree *tree) | |
214 { | |
215 GSList *list = g_slist_append (NULL, tree); | |
216 | |
217 while (list) { | |
218 GtkSmileyTree *t = list->data; | |
219 gint i; | |
220 list = g_slist_remove(list, t); | |
221 if (t->values) { | |
222 for (i = 0; i < t->values->len; i++) | |
223 list = g_slist_append (list, t->children [i]); | |
224 g_string_free (t->values, TRUE); | |
225 g_free (t->children); | |
226 } | |
227 g_free (t); | |
228 } | |
229 } | |
75 | 230 |
76 struct _GtkIMHtmlBit { | 231 struct _GtkIMHtmlBit { |
77 gint type; | 232 gint type; |
78 | 233 |
79 gchar *text; | 234 gchar *text; |
198 gdk_color_free (imhtml->default_bg_color); | 353 gdk_color_free (imhtml->default_bg_color); |
199 | 354 |
200 gdk_cursor_destroy (imhtml->hand_cursor); | 355 gdk_cursor_destroy (imhtml->hand_cursor); |
201 gdk_cursor_destroy (imhtml->arrow_cursor); | 356 gdk_cursor_destroy (imhtml->arrow_cursor); |
202 | 357 |
203 g_hash_table_destroy (imhtml->smiley_hash); | 358 gtk_smiley_tree_destroy (imhtml->smiley_data); |
204 if (imhtml->smiley_start) | |
205 g_string_free (imhtml->smiley_start, TRUE); | |
206 | 359 |
207 if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) | 360 if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) |
208 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | 361 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
209 } | 362 } |
210 | 363 |
1795 | 1948 |
1796 return imhtml_type; | 1949 return imhtml_type; |
1797 } | 1950 } |
1798 | 1951 |
1799 static void | 1952 static void |
1800 gtk_imhtml_init_smiley_hash (GtkIMHtml *imhtml) | 1953 gtk_imhtml_init_smileys (GtkIMHtml *imhtml) |
1801 { | 1954 { |
1802 g_return_if_fail (imhtml != NULL); | 1955 g_return_if_fail (imhtml != NULL); |
1803 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | 1956 g_return_if_fail (GTK_IS_IMHTML (imhtml)); |
1804 | 1957 |
1805 imhtml->smiley_hash = g_hash_table_new (g_str_hash, g_str_equal); | 1958 imhtml->smiley_data = gtk_smiley_tree_new (); |
1806 | 1959 |
1807 gtk_imhtml_associate_smiley (imhtml, ":)", smile_xpm); | 1960 gtk_imhtml_associate_smiley (imhtml, ":)", smile_xpm); |
1808 gtk_imhtml_associate_smiley (imhtml, ":-)", smile_xpm); | 1961 gtk_imhtml_associate_smiley (imhtml, ":-)", smile_xpm); |
1809 | 1962 |
1810 gtk_imhtml_associate_smiley (imhtml, ":(", sad_xpm); | 1963 gtk_imhtml_associate_smiley (imhtml, ":(", sad_xpm); |
1856 imhtml->img = NULL; | 2009 imhtml->img = NULL; |
1857 | 2010 |
1858 imhtml->smileys = TRUE; | 2011 imhtml->smileys = TRUE; |
1859 imhtml->comments = FALSE; | 2012 imhtml->comments = FALSE; |
1860 | 2013 |
1861 imhtml->smin = G_MAXINT; | 2014 gtk_imhtml_init_smileys (imhtml); |
1862 imhtml->smax = 0; | |
1863 gtk_imhtml_init_smiley_hash (imhtml); | |
1864 | 2015 |
1865 return GTK_WIDGET (imhtml); | 2016 return GTK_WIDGET (imhtml); |
1866 } | 2017 } |
1867 | 2018 |
1868 void | 2019 void |
1920 { | 2071 { |
1921 g_return_if_fail (imhtml != NULL); | 2072 g_return_if_fail (imhtml != NULL); |
1922 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | 2073 g_return_if_fail (GTK_IS_IMHTML (imhtml)); |
1923 g_return_if_fail (text != NULL); | 2074 g_return_if_fail (text != NULL); |
1924 | 2075 |
1925 if (strlen (text) < imhtml->smin) | |
1926 imhtml->smin = strlen (text); | |
1927 | |
1928 if (strlen (text) > imhtml->smax) | |
1929 imhtml->smax = strlen (text); | |
1930 | |
1931 if (!imhtml->smiley_start) | |
1932 imhtml->smiley_start = g_string_new (""); | |
1933 | |
1934 if (!strchr (imhtml->smiley_start->str, text [0])) | |
1935 imhtml->smiley_start = g_string_append_c (imhtml->smiley_start, text [0]); | |
1936 | |
1937 if (xpm == NULL) | 2076 if (xpm == NULL) |
1938 g_hash_table_remove (imhtml->smiley_hash, text); | 2077 gtk_smiley_tree_remove (imhtml->smiley_data, text); |
1939 else | 2078 else |
1940 g_hash_table_insert (imhtml->smiley_hash, text, xpm); | 2079 gtk_smiley_tree_insert (imhtml->smiley_data, text, xpm); |
1941 } | 2080 } |
1942 | 2081 |
1943 static void | 2082 static void |
1944 new_line (GtkIMHtml *imhtml) | 2083 new_line (GtkIMHtml *imhtml) |
1945 { | 2084 { |
2246 | 2385 |
2247 static gint | 2386 static gint |
2248 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | 2387 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, |
2249 const gchar *text) | 2388 const gchar *text) |
2250 { | 2389 { |
2251 gchar *tmp; | 2390 return gtk_smiley_tree_lookup (imhtml->smiley_data, text); |
2252 gint i; | |
2253 | |
2254 g_return_val_if_fail (imhtml != NULL, 0); | |
2255 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), 0); | |
2256 g_return_val_if_fail (text != NULL, 0); | |
2257 | |
2258 if (!imhtml->smiley_start || !strchr (imhtml->smiley_start->str, text [0])) | |
2259 return 0; | |
2260 | |
2261 tmp = g_malloc (imhtml->smax + 1); | |
2262 | |
2263 for (i = imhtml->smin; i <= imhtml->smax; i++) { | |
2264 if (strlen (text) < i) { | |
2265 g_free (tmp); | |
2266 return 0; | |
2267 } | |
2268 g_snprintf (tmp, i + 1, "%s", text); | |
2269 if (g_hash_table_lookup (imhtml->smiley_hash, tmp)) { | |
2270 g_free (tmp); | |
2271 return i; | |
2272 } | |
2273 } | |
2274 | |
2275 g_free (tmp); | |
2276 return 0; | |
2277 } | 2391 } |
2278 | 2392 |
2279 static GtkIMHtmlBit * | 2393 static GtkIMHtmlBit * |
2280 gtk_imhtml_new_bit (GtkIMHtml *imhtml, | 2394 gtk_imhtml_new_bit (GtkIMHtml *imhtml, |
2281 gint type, | 2395 gint type, |
2349 clr = (bg != NULL) ? bg : imhtml->default_bg_color; | 2463 clr = (bg != NULL) ? bg : imhtml->default_bg_color; |
2350 | 2464 |
2351 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | 2465 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, |
2352 &bit->bm, | 2466 &bit->bm, |
2353 clr, | 2467 clr, |
2354 g_hash_table_lookup (imhtml->smiley_hash, text)); | 2468 gtk_smiley_tree_image (imhtml->smiley_data, text)); |
2355 } | 2469 } |
2356 | 2470 |
2357 return bit; | 2471 return bit; |
2358 } | 2472 } |
2359 | 2473 |