ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=7489eb6e30f844207afe0267d6d6be8c35f0dc54

commit 7489eb6e30f844207afe0267d6d6be8c35f0dc54
Author: Andy Williams <a...@andywilliams.me>
Date:   Sun Apr 12 17:25:20 2015 +0100

    syntax: don't slow down by repeating tokens
    
    Clear out the token list before each parse callback loops
---
 elm_code/src/lib/elm_code_line.c        | 10 +++++++
 elm_code/src/lib/elm_code_line.h        |  2 ++
 elm_code/src/lib/elm_code_parse.c       |  8 +++++
 elm_code/src/tests/Makefile.am          |  1 +
 elm_code/src/tests/elm_code_suite.h     |  1 +
 elm_code/src/tests/elm_code_test_line.c | 52 +++++++++++++++++++++++++++++++++
 6 files changed, 74 insertions(+)

diff --git a/elm_code/src/lib/elm_code_line.c b/elm_code/src/lib/elm_code_line.c
index dfddb67..852ed36 100644
--- a/elm_code/src/lib/elm_code_line.c
+++ b/elm_code/src/lib/elm_code_line.c
@@ -57,3 +57,13 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int 
start, int end, int l
         elm_code_line_token_add(next_line, 1, end, lines - 1, type);
      }
 }
+
+EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line)
+{
+   Elm_Code_Token *token;
+
+   EINA_LIST_FREE(line->tokens, token)
+     free(token);
+   line->tokens = NULL;
+}
+
diff --git a/elm_code/src/lib/elm_code_line.h b/elm_code/src/lib/elm_code_line.h
index d2f7968..64e3e35 100644
--- a/elm_code/src/lib/elm_code_line.h
+++ b/elm_code/src/lib/elm_code_line.h
@@ -51,6 +51,8 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, 
Elm_Code_Status_Type sta
 
 EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int 
lines, Elm_Code_Token_Type type);
 
+EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line);
+
 /**
  * @}
  */
diff --git a/elm_code/src/lib/elm_code_parse.c 
b/elm_code/src/lib/elm_code_parse.c
index 9146e46..9a70ca4 100644
--- a/elm_code/src/lib/elm_code_parse.c
+++ b/elm_code/src/lib/elm_code_parse.c
@@ -22,6 +22,8 @@ _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line)
    Elm_Code_Parser *parser;
    Eina_List *item;
 
+   elm_code_line_tokens_clear(line);
+
    EINA_LIST_FOREACH(code->parsers, item, parser)
      {
         if (parser->parse_line)
@@ -34,6 +36,12 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file)
 {
    Elm_Code_Parser *parser;
    Eina_List *item;
+   Elm_Code_Line *line;
+
+   EINA_LIST_FOREACH(file->lines, item, line)
+     {
+        elm_code_line_tokens_clear(line);
+     }
 
    EINA_LIST_FOREACH(code->parsers, item, parser)
      {
diff --git a/elm_code/src/tests/Makefile.am b/elm_code/src/tests/Makefile.am
index 8e74bc0..45476e5 100644
--- a/elm_code/src/tests/Makefile.am
+++ b/elm_code/src/tests/Makefile.am
@@ -9,6 +9,7 @@ elm_code_suite_SOURCES = \
 elm_code_file_test_load.c \
 elm_code_file_test_memory.c \
 elm_code_test_basic.c \
+elm_code_test_line.c \
 elm_code_test_parse.c \
 elm_code_test_text.c \
 widget/elm_code_test_widget.c \
diff --git a/elm_code/src/tests/elm_code_suite.h 
b/elm_code/src/tests/elm_code_suite.h
index d03e11b..5a7f4e3 100644
--- a/elm_code/src/tests/elm_code_suite.h
+++ b/elm_code/src/tests/elm_code_suite.h
@@ -8,6 +8,7 @@
 void elm_code_file_test_load(TCase *tc);
 void elm_code_file_test_memory(TCase *tc);
 void elm_code_test_basic(TCase *tc);
+void elm_code_test_line(TCase *tc);
 void elm_code_test_parse(TCase *tc);
 void elm_code_test_text(TCase *tc);
 void elm_code_test_widget(TCase *tc);
diff --git a/elm_code/src/tests/elm_code_test_line.c 
b/elm_code/src/tests/elm_code_test_line.c
new file mode 100644
index 0000000..5d26897
--- /dev/null
+++ b/elm_code/src/tests/elm_code_test_line.c
@@ -0,0 +1,52 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "elm_code_suite.h"
+
+START_TEST (elm_code_line_create_test)
+{
+   Elm_Code *code;
+   Elm_Code_File *file;
+   Elm_Code_Line *line;
+
+   code = elm_code_create();
+   file = elm_code_file_new(code);
+
+   elm_code_file_line_append(file, "a test string...", 16, NULL);
+   line = elm_code_file_line_get(file, 1);
+
+   ck_assert(!!line);
+
+   elm_code_free(code);
+}
+END_TEST
+
+START_TEST (elm_code_line_token_count_test)
+{
+   Elm_Code *code;
+   Elm_Code_File *file;
+   Elm_Code_Line *line;
+
+   code = elm_code_create();
+   file = elm_code_file_new(code);
+
+   elm_code_file_line_append(file, "a test string...", 16, NULL);
+   line = elm_code_file_line_get(file, 1);
+
+   ck_assert_int_eq(0, eina_list_count(line->tokens));
+   elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
+   ck_assert_int_eq(1, eina_list_count(line->tokens));
+   elm_code_line_tokens_clear(line);
+   ck_assert_int_eq(0, eina_list_count(line->tokens));
+
+   elm_code_free(code);
+}
+END_TEST
+
+void elm_code_test_line(TCase *tc)
+{
+   tcase_add_test(tc, elm_code_line_create_test);
+   tcase_add_test(tc, elm_code_line_token_count_test);
+}
+

-- 


Reply via email to