Mercurial > hg > xemacs-beta
diff 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 |
line wrap: on
line diff
--- a/src/syntax.h Fri Feb 14 07:54:29 2003 +0000 +++ b/src/syntax.h Fri Feb 14 09:50:17 2003 +0000 @@ -1,6 +1,6 @@ /* Declarations having to do with XEmacs syntax tables. Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc. - Copyright (C) 2002 Ben Wing. + Copyright (C) 2002, 2003 Ben Wing. This file is part of XEmacs. @@ -72,9 +72,43 @@ enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out); +void update_syntax_table (Lisp_Object table); + +DECLARE_INLINE_HEADER ( +void +update_mirror_syntax_if_dirty (Lisp_Object table) +) +{ + if (XCHAR_TABLE (table)->dirty) + update_syntax_table (table); +} + /* Return the syntax code for a particular character and mirror table. */ -#define SYNTAX_CODE(table, c) XINT (get_char_table (c, table)) +DECLARE_INLINE_HEADER ( +enum syntaxcode +SYNTAX_CODE (Lisp_Object table, Ichar c) +) +{ + type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); + update_mirror_syntax_if_dirty (table); + return (enum syntaxcode) XINT (get_char_table_1 (c, table)); +} + +#ifdef NOT_WORTH_THE_EFFORT + +/* Same but skip the dirty check. */ + +DECLARE_INLINE_HEADER ( +enum syntaxcode +SYNTAX_CODE_1 (Lisp_Object table, Ichar c) +) +{ + type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); + return (enum syntaxcode) XINT (get_char_table_1 (c, table)); +} + +#endif /* NOT_WORTH_THE_EFFORT */ #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177)) @@ -246,8 +280,6 @@ extern int no_quit_in_re_search; -void update_syntax_table (Lisp_Object table); - /****************************** syntax caches ********************************/ @@ -264,8 +296,8 @@ struct syntax_cache { int use_code; /* Whether to use syntax_code or - current_syntax_table. This is - set depending on whether the + syntax_table. This is set + depending on whether the syntax-table property is a syntax table or a syntax code. */ @@ -286,7 +318,8 @@ OBJECT is a buffer, this will always be the same buffer. */ int syntax_code; /* Syntax code of current char. */ - Lisp_Object current_syntax_table; /* Syntax table for current pos. */ + Lisp_Object syntax_table; /* Syntax table for current pos. */ + Lisp_Object mirror_table; /* Mirror table for this table. */ Lisp_Object start, end; /* Markers to keep track of the known region in a buffer. Formerly we used an internal @@ -300,6 +333,8 @@ change. */ }; +extern const struct sized_memory_description syntax_cache_description; + /* Note that the external interface to the syntax-cache uses charpos's, but intnernally we use bytepos's, for speed. */ @@ -348,7 +383,23 @@ #define SYNTAX_CODE_FROM_CACHE(cache, c) \ ((cache)->use_code ? (cache)->syntax_code \ - : SYNTAX_CODE ((cache)->current_syntax_table, c)) + : SYNTAX_CODE ((cache)->mirror_table, c)) + +#ifdef NOT_WORTH_THE_EFFORT +/* If we really cared about the theoretical performance hit of the dirty + check in SYNTAX_CODE, we could use SYNTAX_CODE_1 and endeavor to always + keep the mirror table clean, e.g. by checking for dirtiness at the time + we set up the syntax cache. There are lots of potential problems, of + course -- incomplete understanding of the possible pathways into the + code, with some that are bypassing the setups, Lisp code being executed + in the meantime that could change things (e.g. QUIT is called in many + functions and could execute arbitrary Lisp very easily), etc. The QUIT + problem is the biggest one, probably, and one of the main reasons it's + probably just not worth it. */ +#define SYNTAX_CODE_FROM_CACHE(cache, c) \ + ((cache)->use_code ? (cache)->syntax_code \ + : SYNTAX_CODE_1 ((cache)->mirror_table, c)) +#endif /***************************** syntax code macros ****************************/