Skip to content

Commit

Permalink
Pre allocate
Browse files Browse the repository at this point in the history
  • Loading branch information
rwynn committed Dec 22, 2023
1 parent 94c89d7 commit e052eec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions monstache.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ func opIDToString(op *gtm.Op) string {
}

func convertSliceJavascript(a []interface{}) []interface{} {
var avs []interface{}
avs := make([]interface{}, 0, len(a))
for _, av := range a {
var avc interface{}
switch achild := av.(type) {
Expand All @@ -859,7 +859,7 @@ func convertSliceJavascript(a []interface{}) []interface{} {
}

func convertMapJavascript(e map[string]interface{}) map[string]interface{} {
o := make(map[string]interface{})
o := make(map[string]interface{}, len(e))
for k, v := range e {
switch child := v.(type) {
case map[string]interface{}:
Expand All @@ -876,7 +876,7 @@ func convertMapJavascript(e map[string]interface{}) map[string]interface{} {
}

func fixSlicePruneInvalidJSON(id string, key string, a []interface{}) []interface{} {
var avs []interface{}
avs := make([]interface{}, 0, len(a))
for _, av := range a {
var avc interface{}
switch achild := av.(type) {
Expand Down Expand Up @@ -914,7 +914,7 @@ func fixSlicePruneInvalidJSON(id string, key string, a []interface{}) []interfac
}

func fixPruneInvalidJSON(id string, e map[string]interface{}) map[string]interface{} {
o := make(map[string]interface{})
o := make(map[string]interface{}, len(e))
for k, v := range e {
switch child := v.(type) {
case map[string]interface{}:
Expand Down Expand Up @@ -974,23 +974,23 @@ func deepExportValue(a interface{}) (b interface{}) {
}

func deepExportMapSlice(a []map[string]interface{}) []interface{} {
var avs []interface{}
avs := make([]interface{}, 0, len(a))
for _, av := range a {
avs = append(avs, deepExportMap(av))
}
return avs
}

func deepExportSlice(a []interface{}) []interface{} {
var avs []interface{}
avs := make([]interface{}, 0, len(a))
for _, av := range a {
avs = append(avs, deepExportValue(av))
}
return avs
}

func deepExportMap(e map[string]interface{}) map[string]interface{} {
o := make(map[string]interface{})
o := make(map[string]interface{}, len(e))
for k, v := range e {
o[k] = deepExportValue(v)
}
Expand Down Expand Up @@ -3869,23 +3869,23 @@ func (fc *findCall) restoreIds(v interface{}) (r interface{}) {
r = v
}
case []map[string]interface{}:
var avs []interface{}
avs := make([]interface{}, 0, len(vt))
for _, av := range vt {
mvs := make(map[string]interface{})
mvs := make(map[string]interface{}, len(av))
for k, v := range av {
mvs[k] = fc.restoreIds(v)
}
avs = append(avs, mvs)
}
r = avs
case primitive.A:
var avs []interface{}
avs := make([]interface{}, 0, len(vt))
for _, av := range vt {
avs = append(avs, fc.restoreIds(av))
}
r = avs
case []interface{}:
var avs []interface{}
avs := make([]interface{}, 0, len(vt))
for _, av := range vt {
avs = append(avs, fc.restoreIds(av))
}
Expand Down
2 changes: 1 addition & 1 deletion monstachemap/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ConvertSliceForJSON(a []interface{}) []interface{} {
}

func ConvertMapForJSON(m map[string]interface{}) map[string]interface{} {
o := map[string]interface{}{}
o := make(map[string]interface{}, len(m))
for k, v := range m {
switch child := v.(type) {
case map[string]interface{}:
Expand Down

0 comments on commit e052eec

Please sign in to comment.