From 7beb4c1266c7e25b8498518e3adae1aba5297265 Mon Sep 17 00:00:00 2001 From: Paul Sheer Date: Sat, 25 Apr 1998 11:52:29 +0000 Subject: [PATCH] optimisations to syntax highlighting --- edit/edit.h | 2 ++ edit/syntax.c | 50 +++++++++++++++++++++++++++++++++++++------------- src/ChangeLog | 5 +++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/edit/edit.h b/edit/edit.h index da2185600..27b5f435c 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -235,6 +235,8 @@ struct context_rule { char *whole_word_chars_left; char *whole_word_chars_right; unsigned char *conflicts; + char *keyword_first_chars; + char *keyword_last_chars; /* first word is word[1] */ struct key_word **keyword; }; diff --git a/edit/syntax.c b/edit/syntax.c index 66119742b..723817e4a 100644 --- a/edit/syntax.c +++ b/edit/syntax.c @@ -206,17 +206,18 @@ static unsigned long apply_rules_going_right (WEdit * edit, long i, unsigned lon } /* check to turn on a keyword */ if (!keyword) { - int count; - r = edit->rules[context]; - for (count = 1; r->keyword[count]; count++) { + char *p; + p = (r = edit->rules[context])->keyword_first_chars; + while ((p = strchr (p + 1, c2))) { struct key_word *k; + int count; + count = (unsigned long) p - (unsigned long) r->keyword_first_chars; k = r->keyword[count]; - if (k->first == c2) - if (compare_word_to_right (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start)) { - keyword = count; - debug_printf ("keyword=%d ", keyword); - break; - } + if (compare_word_to_right (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start)) { + keyword = count; + debug_printf ("keyword=%d ", keyword); + break; + } } } debug_printf ("border=%s ", border ? ((border & RULE_ON_LEFT_BORDER) ? "left" : "right") : "off"); @@ -338,10 +339,12 @@ static unsigned long apply_rules_going_left (WEdit * edit, long i, unsigned long } /* check to turn on a keyword */ if (!keyword) { - int count; - r = edit->rules[context]; - for (count = 1; r->keyword[count]; count++) { + char *p; + p = (r = edit->rules[context])->keyword_last_chars; + while ((p = strchr (p + 1, c1))) { struct key_word *k; + int count; + count = (unsigned long) p - (unsigned long) r->keyword_last_chars; k = r->keyword[count]; if (k->last == c1 && compare_word_to_left (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start)) { keyword = count; @@ -697,7 +700,6 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f) result = line; return result; } - for (i = 1; edit->rules[i]; i++) { for (j = i + 1; edit->rules[j]; j++) { if (strstr (edit->rules[j]->right, edit->rules[i]->right) && strcmp (edit->rules[i]->right, "\n")) { @@ -710,6 +712,26 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f) } } + { + char first_chars[1024], *p; + char last_chars[1024], *q; + for (i = 0; edit->rules[i]; i++) { + c = edit->rules[i]; + p = first_chars; + q = last_chars; + *p++ = (char) 1; + *q++ = (char) 1; + for (j = 1; c->keyword[j]; j++) { + *p++ = c->keyword[j]->first; + *q++ = c->keyword[j]->last; + } + *p = '\0'; + *q = '\0'; + c->keyword_first_chars = strdup (first_chars); + c->keyword_last_chars = strdup (last_chars); + } + } + return result; } @@ -749,6 +771,8 @@ void edit_free_syntax_rules (WEdit * edit) syntax_free (edit->rules[i]->whole_word_chars_left); syntax_free (edit->rules[i]->whole_word_chars_right); syntax_free (edit->rules[i]->keyword); + syntax_free (edit->rules[i]->keyword_first_chars); + syntax_free (edit->rules[i]->keyword_last_chars); syntax_free (edit->rules[i]); } syntax_free (edit->rules); diff --git a/src/ChangeLog b/src/ChangeLog index eebc350e9..f1dd0ecc1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Sat Apr 25 13:41:43 1998 Paul Sheer + + * edit.h, syntax.h: some optimisations to improve syntax + highlighting speed. + 1998-04-24 Miguel de Icaza * color.h: Move the CTYPE definition