Skip to content

Commit d5b878b

Browse files
committed
Avoid reallocation of slice's underlying array
We need to increase the cap of the props slice by one to account for CreateFinishedDummyProp
1 parent 54f28e2 commit d5b878b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sendtables/entity.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ func coordFromCell(cell, cellWidth int, offset float64) float64 {
147147

148148
// NewEntity creates a new Entity with a given id and ServerClass and returns it.
149149
func NewEntity(id int, serverClass *ServerClass) *Entity {
150-
props := make([]PropertyEntry, len(serverClass.FlattenedProps))
150+
propCount := len(serverClass.FlattenedProps)
151+
props := make([]PropertyEntry, propCount, propCount+1) // Cap +1 for CreateFinishedDummyProp
151152
for i := range serverClass.FlattenedProps {
152153
props[i] = PropertyEntry{entry: &serverClass.FlattenedProps[i]}
153154
}
155+
154156
return &Entity{ID: id, ServerClass: serverClass, props: props}
155157
}
156158

0 commit comments

Comments
 (0)