Skip to content

Obj.on/emit should always allocate an array #2559

@gfwilliams

Description

@gfwilliams

Right now for one event we reference directly:

a = {};
a.on("foo", print);
trace(a);
#2547[r1,l1] Object {
  #2087[r1,l2] Name String [2 blocks] "#onfoo"    #2088[r1,l0] NativeFunction 0x2751d (16) { }
}

But for two we use an array:

a = {};
a.on("foo", print);
a.on("foo", print);
trace(a);
#2547[r1,l1] Object {
  #2087[r1,l2] Name String [2 blocks] "#onfoo"    #4432[r1,l0] Array(2) [
      #3204[r1,l2] Name Integer 0        #2088[r1,l0] NativeFunction 0x2751d (16) { }
      #4437[r1,l2] Name Integer 1        #5[r1,l0] NativeFunction 0x2751d (16) { }
    ]
}

This saves space, but it has the effect that when events are queued they are either queued referencing the function, or the array, depending on how many handlers there are, which can subtly affect the behaviour.

Given the small overhead (2 vars extra) we should just simplify the code an always use an array, which makes handling the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions