mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
optimisations to syntax highlighting
This commit is contained in:
parent
f037975889
commit
7beb4c1266
@ -235,6 +235,8 @@ struct context_rule {
|
|||||||
char *whole_word_chars_left;
|
char *whole_word_chars_left;
|
||||||
char *whole_word_chars_right;
|
char *whole_word_chars_right;
|
||||||
unsigned char *conflicts;
|
unsigned char *conflicts;
|
||||||
|
char *keyword_first_chars;
|
||||||
|
char *keyword_last_chars;
|
||||||
/* first word is word[1] */
|
/* first word is word[1] */
|
||||||
struct key_word **keyword;
|
struct key_word **keyword;
|
||||||
};
|
};
|
||||||
|
@ -206,17 +206,18 @@ static unsigned long apply_rules_going_right (WEdit * edit, long i, unsigned lon
|
|||||||
}
|
}
|
||||||
/* check to turn on a keyword */
|
/* check to turn on a keyword */
|
||||||
if (!keyword) {
|
if (!keyword) {
|
||||||
int count;
|
char *p;
|
||||||
r = edit->rules[context];
|
p = (r = edit->rules[context])->keyword_first_chars;
|
||||||
for (count = 1; r->keyword[count]; count++) {
|
while ((p = strchr (p + 1, c2))) {
|
||||||
struct key_word *k;
|
struct key_word *k;
|
||||||
|
int count;
|
||||||
|
count = (unsigned long) p - (unsigned long) r->keyword_first_chars;
|
||||||
k = r->keyword[count];
|
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)) {
|
||||||
if (compare_word_to_right (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start)) {
|
keyword = count;
|
||||||
keyword = count;
|
debug_printf ("keyword=%d ", keyword);
|
||||||
debug_printf ("keyword=%d ", keyword);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug_printf ("border=%s ", border ? ((border & RULE_ON_LEFT_BORDER) ? "left" : "right") : "off");
|
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 */
|
/* check to turn on a keyword */
|
||||||
if (!keyword) {
|
if (!keyword) {
|
||||||
int count;
|
char *p;
|
||||||
r = edit->rules[context];
|
p = (r = edit->rules[context])->keyword_last_chars;
|
||||||
for (count = 1; r->keyword[count]; count++) {
|
while ((p = strchr (p + 1, c1))) {
|
||||||
struct key_word *k;
|
struct key_word *k;
|
||||||
|
int count;
|
||||||
|
count = (unsigned long) p - (unsigned long) r->keyword_last_chars;
|
||||||
k = r->keyword[count];
|
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)) {
|
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;
|
keyword = count;
|
||||||
@ -697,7 +700,6 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
|
|||||||
result = line;
|
result = line;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; edit->rules[i]; i++) {
|
for (i = 1; edit->rules[i]; i++) {
|
||||||
for (j = i + 1; edit->rules[j]; j++) {
|
for (j = i + 1; edit->rules[j]; j++) {
|
||||||
if (strstr (edit->rules[j]->right, edit->rules[i]->right) && strcmp (edit->rules[i]->right, "\n")) {
|
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;
|
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_left);
|
||||||
syntax_free (edit->rules[i]->whole_word_chars_right);
|
syntax_free (edit->rules[i]->whole_word_chars_right);
|
||||||
syntax_free (edit->rules[i]->keyword);
|
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[i]);
|
||||||
}
|
}
|
||||||
syntax_free (edit->rules);
|
syntax_free (edit->rules);
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Apr 25 13:41:43 1998 Paul Sheer <psheer@obsidian.co.za>
|
||||||
|
|
||||||
|
* edit.h, syntax.h: some optimisations to improve syntax
|
||||||
|
highlighting speed.
|
||||||
|
|
||||||
1998-04-24 Miguel de Icaza <miguel@nuclecu.unam.mx>
|
1998-04-24 Miguel de Icaza <miguel@nuclecu.unam.mx>
|
||||||
|
|
||||||
* color.h: Move the CTYPE definition
|
* color.h: Move the CTYPE definition
|
||||||
|
Loading…
Reference in New Issue
Block a user