mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-30 11:42:54 +03:00
Merge branch '1843_slow_edit'
* 1843_slow_edit: Some simple optimization of syntax highlighting engine. Ticket #1843: slow syntax highlighting engine in editor.
This commit is contained in:
commit
b9250160f1
15
edit/edit.c
15
edit/edit.c
@ -41,15 +41,11 @@
|
||||
|
||||
#include "../src/global.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "editlock.h"
|
||||
#include "edit-widget.h"
|
||||
#include "../src/cmddef.h"
|
||||
|
||||
#include "../src/tty/color.h" /* EDITOR_NORMAL_COLOR */
|
||||
#include "../src/tty/color.h"
|
||||
#include "../src/tty/tty.h" /* attrset() */
|
||||
#include "../src/tty/key.h" /* is_idle() */
|
||||
#include "../src/skin/skin.h" /* mc_skin_color_get */
|
||||
|
||||
#include "../src/skin/skin.h" /* EDITOR_NORMAL_COLOR */
|
||||
|
||||
#include "../src/widget.h"
|
||||
#include "../src/cmd.h" /* view_other_cmd() */
|
||||
@ -60,6 +56,11 @@
|
||||
#include "../src/charsets.h" /* get_codepage_id */
|
||||
#include "../src/main.h" /* source_codepage */
|
||||
#include "../src/learn.h" /* learn_keys */
|
||||
#include "../src/cmddef.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "editlock.h"
|
||||
#include "edit-widget.h"
|
||||
|
||||
#include "../vfs/vfs.h"
|
||||
|
||||
|
@ -50,6 +50,10 @@
|
||||
#include "../src/tty/tty.h"
|
||||
#include "../src/tty/key.h" /* XCTRL */
|
||||
|
||||
#include "../src/mcconfig/mcconfig.h"
|
||||
|
||||
#include "../src/skin/skin.h"
|
||||
|
||||
#include "../src/history.h"
|
||||
#include "../src/widget.h" /* listbox_new() */
|
||||
#include "../src/layout.h" /* clr_scr() */
|
||||
@ -59,15 +63,13 @@
|
||||
#include "../src/charsets.h"
|
||||
#include "../src/selcodepage.h"
|
||||
#include "../src/strutil.h" /* utf string functions */
|
||||
#include "../src/mcconfig/mcconfig.h"
|
||||
#include "../src/skin/skin.h" /* mc_skin_color_get */
|
||||
#include "../src/cmddef.h"
|
||||
|
||||
#include "../vfs/vfs.h"
|
||||
|
||||
#include "../edit/edit-impl.h"
|
||||
#include "../edit/edit.h"
|
||||
#include "../edit/editlock.h"
|
||||
#include "../src/cmddef.h"
|
||||
#include "../edit/edit-widget.h"
|
||||
#include "../edit/editcmd_dialogs.h"
|
||||
#include "../edit/etags.h"
|
||||
|
@ -48,20 +48,17 @@
|
||||
|
||||
#include "../src/global.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
|
||||
#include "../src/search/search.h" /* search engine */
|
||||
|
||||
#include "../src/skin/skin.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
|
||||
#include "../src/main.h" /* mc_home */
|
||||
#include "../src/wtools.h" /* message() */
|
||||
#include "../src/strutil.h" /* utf string functions */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
|
||||
/* bytes */
|
||||
#define SYNTAX_MARKER_DENSITY 512
|
||||
|
||||
@ -136,7 +133,7 @@ destroy_defines (GTree **defines)
|
||||
{
|
||||
g_tree_traverse (*defines, mc_defines_destroy, G_POST_ORDER, NULL);
|
||||
g_tree_destroy (*defines);
|
||||
*defines = 0;
|
||||
*defines = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -459,7 +456,7 @@ static struct syntax_rule edit_get_rule (WEdit * edit, long byte_index)
|
||||
struct _syntax_marker *s;
|
||||
|
||||
s = edit->syntax_marker;
|
||||
edit->syntax_marker = g_malloc0 (sizeof (struct _syntax_marker));
|
||||
edit->syntax_marker = g_malloc (sizeof (struct _syntax_marker));
|
||||
edit->syntax_marker->next = s;
|
||||
edit->syntax_marker->offset = i;
|
||||
edit->syntax_marker->rule = edit->rule;
|
||||
@ -482,7 +479,7 @@ static struct syntax_rule edit_get_rule (WEdit * edit, long byte_index)
|
||||
break;
|
||||
}
|
||||
s = edit->syntax_marker->next;
|
||||
MC_PTR_FREE (edit->syntax_marker);
|
||||
g_free (edit->syntax_marker);
|
||||
edit->syntax_marker = s;
|
||||
}
|
||||
}
|
||||
@ -493,20 +490,19 @@ static struct syntax_rule edit_get_rule (WEdit * edit, long byte_index)
|
||||
static inline void
|
||||
translate_rule_to_color (WEdit * edit, struct syntax_rule rule, int *color)
|
||||
{
|
||||
struct key_word *k;
|
||||
|
||||
k = edit->rules[rule.context]->keyword[rule.keyword];
|
||||
*color = k->color;
|
||||
*color = edit->rules[rule.context]->keyword[rule.keyword]->color;
|
||||
}
|
||||
|
||||
void edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
|
||||
void
|
||||
edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
|
||||
{
|
||||
if (edit->rules && byte_index < edit->last_byte &&
|
||||
option_syntax_highlighting && tty_use_colors ()) {
|
||||
if (!tty_use_colors ())
|
||||
*color = 0;
|
||||
else if (edit->rules && byte_index < edit->last_byte &&
|
||||
option_syntax_highlighting)
|
||||
translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color);
|
||||
} else {
|
||||
*color = tty_use_colors () ? mc_skin_color_get("editor", "_default_") : 0;
|
||||
}
|
||||
else
|
||||
*color = EDITOR_NORMAL_COLOR;
|
||||
}
|
||||
|
||||
|
||||
@ -515,12 +511,18 @@ void edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
|
||||
including the newline. Result must be free'd.
|
||||
In case of an error, *line will not be modified.
|
||||
*/
|
||||
static int read_one_line (char **line, FILE * f)
|
||||
static size_t
|
||||
read_one_line (char **line, FILE *f)
|
||||
{
|
||||
GString *p = g_string_new ("");
|
||||
int c, r = 0;
|
||||
GString *p;
|
||||
size_t r = 0;
|
||||
|
||||
/* not reallocate string too often */
|
||||
p = g_string_sized_new (64);
|
||||
|
||||
for (;;) {
|
||||
int c;
|
||||
|
||||
c = fgetc (f);
|
||||
if (c == EOF) {
|
||||
if (ferror (f)) {
|
||||
@ -531,25 +533,26 @@ static int read_one_line (char **line, FILE * f)
|
||||
break;
|
||||
}
|
||||
r++;
|
||||
|
||||
/* handle all of \r\n, \r, \n correctly. */
|
||||
if (c == '\n')
|
||||
break;
|
||||
if (c == '\r') {
|
||||
if ( (c = fgetc (f)) == '\n')
|
||||
c = fgetc (f);
|
||||
if (c == '\n')
|
||||
r++;
|
||||
else
|
||||
ungetc (c, f);
|
||||
break;
|
||||
}
|
||||
if (c == '\n')
|
||||
break;
|
||||
|
||||
g_string_append_c (p, c);
|
||||
}
|
||||
if (r != 0) {
|
||||
*line = p->str;
|
||||
g_string_free (p, FALSE);
|
||||
} else {
|
||||
if (r != 0)
|
||||
*line = g_string_free (p, FALSE);
|
||||
else
|
||||
g_string_free (p, TRUE);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -708,14 +711,14 @@ static FILE *open_include_file (const char *filename)
|
||||
static int
|
||||
edit_read_syntax_rules (WEdit *edit, FILE *f, char **args, int args_size)
|
||||
{
|
||||
FILE *g = 0;
|
||||
FILE *g = NULL;
|
||||
char *fg, *bg;
|
||||
char last_fg[32] = "", last_bg[32] = "";
|
||||
char whole_right[512];
|
||||
char whole_left[512];
|
||||
char *l = 0;
|
||||
int save_line = 0, line = 0;
|
||||
struct context_rule **r, *c = 0;
|
||||
struct context_rule **r, *c = NULL;
|
||||
int num_words = -1, num_contexts = -1;
|
||||
int result = 0;
|
||||
int argc;
|
||||
@ -739,7 +742,7 @@ edit_read_syntax_rules (WEdit *edit, FILE *f, char **args, int args_size)
|
||||
|
||||
line++;
|
||||
l = 0;
|
||||
if (!read_one_line (&l, f)) {
|
||||
if (read_one_line (&l, f) == 0) {
|
||||
if (g) {
|
||||
fclose (f);
|
||||
f = g;
|
||||
@ -747,7 +750,7 @@ edit_read_syntax_rules (WEdit *edit, FILE *f, char **args, int args_size)
|
||||
line = save_line + 1;
|
||||
MC_PTR_FREE (error_file_name);
|
||||
MC_PTR_FREE (l);
|
||||
if (!read_one_line (&l, f))
|
||||
if (read_one_line (&l, f) == 0)
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
@ -966,7 +969,7 @@ edit_read_syntax_rules (WEdit *edit, FILE *f, char **args, int args_size)
|
||||
{
|
||||
char *first_chars, *p;
|
||||
|
||||
first_chars = g_malloc (max_alloc_words_per_context + 2);
|
||||
first_chars = g_malloc0 (max_alloc_words_per_context + 2);
|
||||
|
||||
for (i = 0; edit->rules[i]; i++) {
|
||||
c = edit->rules[i];
|
||||
@ -984,9 +987,10 @@ edit_read_syntax_rules (WEdit *edit, FILE *f, char **args, int args_size)
|
||||
return result;
|
||||
}
|
||||
|
||||
void edit_free_syntax_rules (WEdit * edit)
|
||||
void
|
||||
edit_free_syntax_rules (WEdit * edit)
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
|
||||
if (!edit)
|
||||
return;
|
||||
@ -997,7 +1001,6 @@ void edit_free_syntax_rules (WEdit * edit)
|
||||
|
||||
edit_get_rule (edit, -1);
|
||||
MC_PTR_FREE (edit->syntax_type);
|
||||
edit->syntax_type = 0;
|
||||
|
||||
for (i = 0; edit->rules[i]; i++) {
|
||||
if (edit->rules[i]->keyword) {
|
||||
@ -1019,7 +1022,7 @@ void edit_free_syntax_rules (WEdit * edit)
|
||||
|
||||
while (edit->syntax_marker) {
|
||||
struct _syntax_marker *s = edit->syntax_marker->next;
|
||||
MC_PTR_FREE (edit->syntax_marker);
|
||||
g_free (edit->syntax_marker);
|
||||
edit->syntax_marker = s;
|
||||
}
|
||||
|
||||
@ -1035,7 +1038,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
{
|
||||
#define NENTRIES 30
|
||||
FILE *f, *g = NULL;
|
||||
char *args[1024], *l = 0;
|
||||
char *args[1024], *l = NULL;
|
||||
int line = 0;
|
||||
int result = 0;
|
||||
int count = 0;
|
||||
@ -1056,7 +1059,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
for (;;) {
|
||||
line++;
|
||||
MC_PTR_FREE (l);
|
||||
if (!read_one_line (&l, f))
|
||||
if (read_one_line (&l, f) == 0)
|
||||
break;
|
||||
(void)get_args (l, args, 1023); /* Final NULL */
|
||||
if (!args[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user