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)].
Thanks for any help.
-- Mariano http://marianopeck.wordpress.com