diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-01 01:23:54 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-02 14:40:46 +0900 |
commit | edbca717ae82aea7cd4b693c907581531ba37706 (patch) | |
tree | 5d363fdabd6df90e7f4fbd619be759fc6ae55724 /compiler/parser_test.go | |
parent | Add character property expression (Meet RL1.2 of UTS #18 partially) (diff) | |
download | tre-edbca717ae82aea7cd4b693c907581531ba37706.tar.gz tre-edbca717ae82aea7cd4b693c907581531ba37706.tar.xz |
Improve compilation time a little
A pattern like \p{Letter} generates an AST with many symbols concatenated by alt operators,
which results in a large number of symbol positions in one state of the DFA.
Such a pattern increases the compilation time. This commit improves the compilation time a little better.
- To avoid calling astNode#first and astNode#last recursively, memoize the result of them.
- Use a byte sequence that symbol positions are encoded to as a hash value to avoid using fmt.Fprintf function.
- Implement a sort function for symbol positions instead of using sort.Slice function.
Diffstat (limited to 'compiler/parser_test.go')
-rw-r--r-- | compiler/parser_test.go | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/compiler/parser_test.go b/compiler/parser_test.go index 5a138ab..79f89ff 100644 --- a/compiler/parser_test.go +++ b/compiler/parser_test.go @@ -3,7 +3,6 @@ package compiler import ( "bytes" "fmt" - "os" "reflect" "testing" ) @@ -1118,7 +1117,7 @@ func TestParse(t *testing.T) { if root == nil { t.Fatal("root of AST is nil") } - printAST(os.Stdout, root, "", "", false) + // printAST(os.Stdout, root, "", "", false) { expectedAST := genConcatNode( |