parser.leg: mk_element: preallocate slices of elements
This commit is contained in:
parent
a77ab2f820
commit
61becb6c37
14
parser.leg
14
parser.leg
@ -24,6 +24,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Semantic value of a parsing action.
|
// Semantic value of a parsing action.
|
||||||
@ -790,8 +791,19 @@ func concat_string_list(list *element) string {
|
|||||||
|
|
||||||
/* mk_element - generic constructor for element
|
/* mk_element - generic constructor for element
|
||||||
*/
|
*/
|
||||||
|
var elbuf []element
|
||||||
|
var elock sync.Mutex
|
||||||
|
|
||||||
func mk_element(key int) *element {
|
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
|
/* mk_str - constructor for STR element
|
||||||
|
Loading…
Reference in New Issue
Block a user