Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Change names access helper to iterate over the ancestors instead of doing dup/shift #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TikiTDO
Copy link

@TikiTDO TikiTDO commented Apr 28, 2016

Due to setup of the helper calling the get or set methods on any js object bound to a ruby object will call the accessibe_names each time. This will result in the duplication of the ancestors array which will be used for iteration and then discarded, which is quite inefficient if you plan on calling into ruby often.

Note, an identical and even faster effect could be achieved by refactoring the class to testing where a method is defined using a process like this:

def method_below_object
  begin
    ancestors = obj.class.ancestors
    index_of_object = ancestors.index(Object)
    index_of_method_owner = ancestors.index(obj.method(name).owner)
    return index_of_method_owner < index_of_object
  rescue
    return false
  end
end

I can implement the change if there is interest.

…oing dup/shift

Due to setup of the helper calling the get or set methods on any object bound to a ruby object will call the accessibe_names each time. This will result in the creation of an new array which will be used for iteration and then discarded, which is quite inefficient if you plan on calling into ruby often.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant