Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gfwilliams opened this issue Sep 17, 2024 · 0 comments
Closed

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

gfwilliams opened this issue Sep 17, 2024 · 0 comments

Comments

@gfwilliams
Copy link
Member

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.

gfwilliams added a commit that referenced this issue Oct 25, 2024
…handlers being called for the event that's currently being handled (#2559)
gfwilliams added a commit that referenced this issue Nov 4, 2024
…handlers being called for the event that's currently being handled (#2559)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant