#40 reduce memory allocations for position.Position by using sync.Pool

This commit is contained in:
z7zmey
2018-06-12 21:14:11 +03:00
parent 2737e98559
commit bfc346ebab
5 changed files with 186 additions and 94 deletions

View File

@@ -61,7 +61,8 @@ func (l *Parser) Parse() int {
l.comments = parser.Comments{}
l.positions = parser.Positions{}
l.positionBuilder = &parser.PositionBuilder{
Positions: &l.positions,
Positions: &l.positions,
PositionPool: &l.PositionPool,
}
// parse
@@ -122,6 +123,7 @@ func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) {
for i := 1; i < len(yyDollar); i++ {
if yyDollar[i].token != nil {
p.TokenPool.Put(yyDollar[i].token)
p.PositionPool.Put(yyDollar[i].token.Position)
}
yyDollar[i].token = nil
}