Skip to content

Commit

Permalink
reduce slice allocation when NODE_DICT type conversion
Browse files Browse the repository at this point in the history
Before:
         .          .    375:
         .          .    376:   case NODE_DICT:
         .          .    377:           var kvs []ast.KeyValue
         .          .    378:           for _, nn := range n.value.([]interface{}) {
         .          .    379:                   kv := nn.([]interface{})
         .        3MB    380:                   k := newAstNode(kv[0].(*VimNode))
         .     2.50MB    381:                   v := newAstNode(kv[1].(*VimNode))
       5MB        5MB    382:                   kvs = append(kvs, ast.KeyValue{Key: k, Value: v})
         .          .    383:           }
         .          .    384:           return &ast.Dict{
         .          .    385:                   Lcurlybrace: pos,
         .          .    386:                   Entries:     kvs,
         .          .    387:           }
         .          .    388:

After:
         .          .    375:
         .          .    376:   case NODE_DICT:
         .          .    377:           entries := n.value.([]interface{})
       2MB        2MB    378:           kvs := make([]ast.KeyValue, 0, len(entries))
         .          .    379:           for _, nn := range entries {
         .          .    380:                   kv := nn.([]interface{})
         .     3.50MB    381:                   k := newAstNode(kv[0].(*VimNode))
         .     3.50MB    382:                   v := newAstNode(kv[1].(*VimNode))
         .          .    383:                   kvs = append(kvs, ast.KeyValue{Key: k, Value: v})
         .          .    384:           }
         .          .    385:           return &ast.Dict{
         .          .    386:                   Lcurlybrace: pos,
       1MB        1MB    387:                   Entries:     kvs,
         .          .    388:           }
  • Loading branch information
haya14busa committed Sep 19, 2016
1 parent 2ff688a commit 47a8076
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions go/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ func newAstNode(n *VimNode) ast.Node {
}

case NODE_DICT:
var kvs []ast.KeyValue
for _, nn := range n.value.([]interface{}) {
entries := n.value.([]interface{})
kvs := make([]ast.KeyValue, 0, len(entries))
for _, nn := range entries {
kv := nn.([]interface{})
k := newAstNode(kv[0].(*VimNode))
v := newAstNode(kv[1].(*VimNode))
Expand Down

0 comments on commit 47a8076

Please sign in to comment.