Skip to content

Commit 9ba5cab

Browse files
committed
let observers escape to heap
1 parent af1dd97 commit 9ba5cab

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

ecs/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ type observerManager struct {
122122
}
123123

124124
// newObserverManager creates anew empty observerManager.
125-
func newObserverManager() observerManager {
125+
func newObserverManager() *observerManager {
126126
maxEvents := math.MaxUint8 + 1
127-
return observerManager{
127+
return &observerManager{
128128
observers: make([][]*observerData, maxEvents),
129129
hasObservers: make([]bool, maxEvents),
130130
anyNoComps: make([]bool, maxEvents),

ecs/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type storage struct {
1313
entities []entityIndex // Entity positions in archetypes, indexed by entity ID
1414
isTarget []bool // Whether each entity is a target of a relationship
1515
graph graph // Graph for fast archetype traversal
16-
slices *slices // Slices for internal re-use
1716
archetypes []archetype // All archetypes
1817
allArchetypes []archetypeID // list of all archetype IDs to simplify usage of componentIndex
1918
componentIndex [][]archetypeID // Archetypes indexed by components IDs; each archetype appears under all its component IDs
@@ -24,8 +23,9 @@ type storage struct {
2423
entityPool entityPool // Entity pool for creation and recycling
2524
registry componentRegistry // Component registry
2625
locks lock // World locks
27-
observers observerManager // Observer/event manager
2826
config config // Storage configuration (initial capacities)
27+
slices *slices // Slices for internal re-use
28+
observers *observerManager // Observer/event manager
2929
}
3030

3131
// componentStorage is an index for faster access of table columns by component ID.

ecs/world_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func TestWorldReset(t *testing.T) {
488488
expectEqual(t, 4, query.Count())
489489
query.Close()
490490

491-
obs := &world.storage.observers
491+
obs := world.storage.observers
492492
expectEqual(t, maxObserverID, o.id)
493493
expectTrue(t, obs.allComps[OnCreateEntity].IsZero())
494494
expectTrue(t, obs.allWith[OnCreateEntity].IsZero())

0 commit comments

Comments
 (0)