From 61becb6c37d32446406403188aa88cee69e4395b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Mon, 13 Dec 2010 17:49:24 +0100 Subject: [PATCH] parser.leg: mk_element: preallocate slices of elements --- parser.leg | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/parser.leg b/parser.leg index e2407f3..54a6b06 100644 --- a/parser.leg +++ b/parser.leg @@ -24,6 +24,7 @@ import ( "fmt" "strings" "log" + "sync" ) // Semantic value of a parsing action. @@ -790,8 +791,19 @@ func concat_string_list(list *element) string { /* mk_element - generic constructor for element */ +var elbuf []element +var elock sync.Mutex + func mk_element(key int) *element { - return &element{key: key} + elock.Lock() + if len(elbuf) == 0 { + elbuf = make([]element, 1024) + } + e := &elbuf[0] + elbuf = elbuf[1:] + elock.Unlock() + e.key = key + return e } /* mk_str - constructor for STR element