Skip to content

Commit 2a31979

Browse files
authored
Preallocate types slice in getLiteralTypeFromProperties (#2458)
1 parent f726edf commit 2a31979

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

internal/checker/checker.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25953,11 +25953,13 @@ func (c *Checker) getLiteralTypeFromProperties(t *Type, include TypeFlags, inclu
2595325953
if includeOrigin && t.objectFlags&(ObjectFlagsClassOrInterface|ObjectFlagsReference) != 0 || t.alias != nil {
2595425954
origin = c.newIndexType(t, IndexFlagsNone)
2595525955
}
25956-
var types []*Type
25957-
for _, prop := range c.getPropertiesOfType(t) {
25956+
props := c.getPropertiesOfType(t)
25957+
indexInfos := c.getIndexInfosOfType(t)
25958+
types := make([]*Type, 0, len(props)+len(indexInfos))
25959+
for _, prop := range props {
2595825960
types = append(types, c.getLiteralTypeFromProperty(prop, include, false))
2595925961
}
25960-
for _, info := range c.getIndexInfosOfType(t) {
25962+
for _, info := range indexInfos {
2596125963
if info != c.enumNumberIndexInfo && c.isKeyTypeIncluded(info.keyType, include) {
2596225964
if info.keyType == c.stringType && include&TypeFlagsNumber != 0 {
2596325965
types = append(types, c.stringOrNumberType)

0 commit comments

Comments
 (0)