From edbca717ae82aea7cd4b693c907581531ba37706 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 1 May 2021 01:23:54 +0900 Subject: 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. --- compiler/parser_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'compiler/parser_test.go') 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( -- cgit v1.2.3