Mercurial > hg > xemacs-beta
comparison src/syntax.h @ 1296:87084e8445a7
[xemacs-hg @ 2003-02-14 09:50:15 by ben]
syntax-table fixes
1. the updating of mirror tables every time a syntax table was modified
was taking up huge amounts of time so i added a dirty flag and made the
updating "just-in-time".
2. no-longer-used char-table-entries were not getting "freed", generating
tons of garbage.
3. syntax_match() was being incorrectly called on mirror tables in the
cache, not the original syntax table.
buffer.c, syntax.c: Move syntax table description from buffer.c to syntax.c.
chartab.c, chartab.h: Free extra char table entries to avoid excessive garbage.
Add flags for dirty and mirror_table_p to char tables.
Add a back pointer from mirror tables to the original syntax table.
When modifying a syntax table, don't update the mirror table right
away, just mark as dirty.
Add various asserts to make sure we are dealing with the right type
of table (mirror or non-mirror).
font-lock.c, syntax.c, syntax.h: Add entry to syntax caches for the non-mirror table. Set it
appropriately when initializing the syntax table. Use it, not
the mirror table, for calls to syntax_match().
Don't create a bogus float each time, just once at startup.
Add some asserts, as in chartab.c.
syntax.h: When retrieving the syntax code, check the dirty flag and update
the mirror tables as appropriate.
Add some asserts, as above.
author | ben |
---|---|
date | Fri, 14 Feb 2003 09:50:17 +0000 |
parents | 804517e16990 |
children | 70921960b980 |
comparison
equal
deleted
inserted
replaced
1295:064ef1d07d63 | 1296:87084e8445a7 |
---|---|
1 /* Declarations having to do with XEmacs syntax tables. | 1 /* Declarations having to do with XEmacs syntax tables. |
2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc. | 2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc. |
3 Copyright (C) 2002 Ben Wing. | 3 Copyright (C) 2002, 2003 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
70 }; | 70 }; |
71 | 71 |
72 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, | 72 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, |
73 int *multi_p_out); | 73 int *multi_p_out); |
74 | 74 |
75 void update_syntax_table (Lisp_Object table); | |
76 | |
77 DECLARE_INLINE_HEADER ( | |
78 void | |
79 update_mirror_syntax_if_dirty (Lisp_Object table) | |
80 ) | |
81 { | |
82 if (XCHAR_TABLE (table)->dirty) | |
83 update_syntax_table (table); | |
84 } | |
85 | |
75 /* Return the syntax code for a particular character and mirror table. */ | 86 /* Return the syntax code for a particular character and mirror table. */ |
76 | 87 |
77 #define SYNTAX_CODE(table, c) XINT (get_char_table (c, table)) | 88 DECLARE_INLINE_HEADER ( |
89 enum syntaxcode | |
90 SYNTAX_CODE (Lisp_Object table, Ichar c) | |
91 ) | |
92 { | |
93 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); | |
94 update_mirror_syntax_if_dirty (table); | |
95 return (enum syntaxcode) XINT (get_char_table_1 (c, table)); | |
96 } | |
97 | |
98 #ifdef NOT_WORTH_THE_EFFORT | |
99 | |
100 /* Same but skip the dirty check. */ | |
101 | |
102 DECLARE_INLINE_HEADER ( | |
103 enum syntaxcode | |
104 SYNTAX_CODE_1 (Lisp_Object table, Ichar c) | |
105 ) | |
106 { | |
107 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); | |
108 return (enum syntaxcode) XINT (get_char_table_1 (c, table)); | |
109 } | |
110 | |
111 #endif /* NOT_WORTH_THE_EFFORT */ | |
78 | 112 |
79 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177)) | 113 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177)) |
80 | 114 |
81 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c)) | 115 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c)) |
82 | 116 |
244 syntax table itself. */ | 278 syntax table itself. */ |
245 Lisp_Object syntax_match (Lisp_Object table, Ichar ch); | 279 Lisp_Object syntax_match (Lisp_Object table, Ichar ch); |
246 | 280 |
247 extern int no_quit_in_re_search; | 281 extern int no_quit_in_re_search; |
248 | 282 |
249 void update_syntax_table (Lisp_Object table); | |
250 | |
251 | 283 |
252 /****************************** syntax caches ********************************/ | 284 /****************************** syntax caches ********************************/ |
253 | 285 |
254 extern int lookup_syntax_properties; | 286 extern int lookup_syntax_properties; |
255 | 287 |
262 need to recalculate, we can update the info from the previous info | 294 need to recalculate, we can update the info from the previous info |
263 faster than if we did the whole calculation from scratch. */ | 295 faster than if we did the whole calculation from scratch. */ |
264 struct syntax_cache | 296 struct syntax_cache |
265 { | 297 { |
266 int use_code; /* Whether to use syntax_code or | 298 int use_code; /* Whether to use syntax_code or |
267 current_syntax_table. This is | 299 syntax_table. This is set |
268 set depending on whether the | 300 depending on whether the |
269 syntax-table property is a | 301 syntax-table property is a |
270 syntax table or a syntax | 302 syntax table or a syntax |
271 code. */ | 303 code. */ |
272 int no_syntax_table_prop; /* If non-zero, there was no | 304 int no_syntax_table_prop; /* If non-zero, there was no |
273 `syntax-table' property on the | 305 `syntax-table' property on the |
284 syntax tables, or 0 for the | 316 syntax tables, or 0 for the |
285 standard syntax table. If | 317 standard syntax table. If |
286 OBJECT is a buffer, this will | 318 OBJECT is a buffer, this will |
287 always be the same buffer. */ | 319 always be the same buffer. */ |
288 int syntax_code; /* Syntax code of current char. */ | 320 int syntax_code; /* Syntax code of current char. */ |
289 Lisp_Object current_syntax_table; /* Syntax table for current pos. */ | 321 Lisp_Object syntax_table; /* Syntax table for current pos. */ |
322 Lisp_Object mirror_table; /* Mirror table for this table. */ | |
290 Lisp_Object start, end; /* Markers to keep track of the | 323 Lisp_Object start, end; /* Markers to keep track of the |
291 known region in a buffer. | 324 known region in a buffer. |
292 Formerly we used an internal | 325 Formerly we used an internal |
293 extent, but it seems that having | 326 extent, but it seems that having |
294 an extent over the entire buffer | 327 an extent over the entire buffer |
298 change. */ | 331 change. */ |
299 Charxpos prev_change; /* Position of the previous extent | 332 Charxpos prev_change; /* Position of the previous extent |
300 change. */ | 333 change. */ |
301 }; | 334 }; |
302 | 335 |
336 extern const struct sized_memory_description syntax_cache_description; | |
337 | |
303 /* Note that the external interface to the syntax-cache uses charpos's, but | 338 /* Note that the external interface to the syntax-cache uses charpos's, but |
304 intnernally we use bytepos's, for speed. */ | 339 intnernally we use bytepos's, for speed. */ |
305 | 340 |
306 void update_syntax_cache (struct syntax_cache *cache, Charxpos pos, int count); | 341 void update_syntax_cache (struct syntax_cache *cache, Charxpos pos, int count); |
307 struct syntax_cache *setup_syntax_cache (struct syntax_cache *cache, | 342 struct syntax_cache *setup_syntax_cache (struct syntax_cache *cache, |
346 #define SYNTAX_FROM_CACHE(cache, c) \ | 381 #define SYNTAX_FROM_CACHE(cache, c) \ |
347 SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (cache, c)) | 382 SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (cache, c)) |
348 | 383 |
349 #define SYNTAX_CODE_FROM_CACHE(cache, c) \ | 384 #define SYNTAX_CODE_FROM_CACHE(cache, c) \ |
350 ((cache)->use_code ? (cache)->syntax_code \ | 385 ((cache)->use_code ? (cache)->syntax_code \ |
351 : SYNTAX_CODE ((cache)->current_syntax_table, c)) | 386 : SYNTAX_CODE ((cache)->mirror_table, c)) |
387 | |
388 #ifdef NOT_WORTH_THE_EFFORT | |
389 /* If we really cared about the theoretical performance hit of the dirty | |
390 check in SYNTAX_CODE, we could use SYNTAX_CODE_1 and endeavor to always | |
391 keep the mirror table clean, e.g. by checking for dirtiness at the time | |
392 we set up the syntax cache. There are lots of potential problems, of | |
393 course -- incomplete understanding of the possible pathways into the | |
394 code, with some that are bypassing the setups, Lisp code being executed | |
395 in the meantime that could change things (e.g. QUIT is called in many | |
396 functions and could execute arbitrary Lisp very easily), etc. The QUIT | |
397 problem is the biggest one, probably, and one of the main reasons it's | |
398 probably just not worth it. */ | |
399 #define SYNTAX_CODE_FROM_CACHE(cache, c) \ | |
400 ((cache)->use_code ? (cache)->syntax_code \ | |
401 : SYNTAX_CODE_1 ((cache)->mirror_table, c)) | |
402 #endif | |
352 | 403 |
353 | 404 |
354 /***************************** syntax code macros ****************************/ | 405 /***************************** syntax code macros ****************************/ |
355 | 406 |
356 #define SYNTAX_CODE_PREFIX(c) \ | 407 #define SYNTAX_CODE_PREFIX(c) \ |