On Sat, Sep 17, 2011 at 10:26 PM, Nicolas Cellier < nicolas.cellier.aka.nice@gmail.com> wrote:
2011/9/17 Mariano Martinez Peck <marianopeck@gmail.com>:
Hi guys. I was checking MethodDictionary >> rehash and this is terribly slow because of the #become. Then I saw #rehashWithoutBecome but it answers a different instance. I need a #rehash that does the rehash in the real object and answers self. So...I need the regular #rehash but I want to avoid the #become. Is that possible somehow?
This is the current implementation:
rehashWithoutBecome
| newInstance | newInstance := self species new: self basicSize - 1. "Make sure it has the same capacity" 1 to: self basicSize do: [ :index | (self basicAt: index) ifNotNil: [ :key | newInstance at: key put: (array at: index) ] ]. ^newInstance
I am terrible bad with Collection and friends, but cannot we do soemthing like this:
rehashWithoutBecome
| newInstance | newInstance := self species new: self basicSize - 1. "Make sure it has the same capacity"
1 to: self basicSize do: [ :index | (self basicAt: index) ifNotNil: [ :key | newInstance at: key put: (array at: index) ] ].
1 to: newInstance basicSize do: [ :index | (newInstance basicAt: index) ifNotNil: [ :key | self at: key put: (newInstance array at: index) ] ].
^ self
I guess you should at least also copy the nil entries... Maybe something like
1 to: newInstance basicSize do: [ :index | self basicAt: index put: (newInstance basicAt: index). array at: index put: (newInstance array at: index)].
Good point. So....I was not that mistaken ;) I have just replaced CompiledMethod >> hash with this new method and at least all the tests in MethodDictionaryTest are green. Do you think this implementation is correct or there can be problems? because it is really MUCH faster than the original one. Thanks in advance
Thanks for any help.
-- Mariano http://marianopeck.wordpress.com
-- Mariano http://marianopeck.wordpress.com