Squeak Class Documentation category index | class index  
 
MethodDictionary
  category: Kernel-Methods
  superclass: Dictionary
  subclasses:

I am just like a normal Dictionary, except that I am implemented differently. Each Class has an instances of MethodDictionary to hold the correspondence between selectors (names of methods) and methods themselves.

In a normal Dictionary, the instance variable 'array' holds an array of Associations. Since there are thousands of methods in the system, these Associations waste space.

Each MethodDictionary is a variable object, with the list of keys (selector Symbols) in the variable part of the instance. The variable 'array' holds the values, which are CompiledMethods.

instance methods
  accessing
  add:
at:ifAbsent:
at:put:
at:putNoBecome:
includesKey:
keyAtIdentityValue:ifAbsent:
keyAtValue:ifAbsent:

  enumeration
  associationsDo:
do:
keysAndValuesDo:
keysDo:
valuesDo:

  private
  copy
fullCheckNoBecome
grow
growNoBecome
keyAt:
methodArray
rehash
rehashWithoutBecome
removeDangerouslyKey:ifAbsent:
scanFor:
swap:with:

  removing
  removeKey:ifAbsent:
removeKeyNoBecome:

class methods
  instance creation
  new
new:

instance methods
  accessing top  
 

add:

Include newObject as one of the receiver's elements, but only if
not already present. Answer newObject.


 

at:ifAbsent:

Answer the value associated with the key or, if key isn't found,
answer the result of evaluating aBlock.


 

at:put:

Set the value at key to be value.


 

at:putNoBecome:

Set the value at key to be value. Answer the resulting MethodDictionary


 

includesKey:

This override assumes that pointsTo is a fast primitive


 

keyAtIdentityValue:ifAbsent:

Answer the key whose value equals the argument, value. If there is
none, answer the result of evaluating exceptionBlock.


 

keyAtValue:ifAbsent:

Answer the key whose value equals the argument, value. If there is
none, answer the result of evaluating exceptionBlock.


  enumeration top  
 

associationsDo:

Evaluate aBlock for each of the receiver's elements (key/value
associations).


 

do:

Evaluate aBlock with each of the receiver's elements as the argument.


 

keysAndValuesDo:

Enumerate the receiver with all the keys and values passed to the block


 

keysDo:

Evaluate aBlock for each of the receiver's keys.


 

valuesDo:

Evaluate aBlock for each of the receiver's keys.


  private top  
 

copy

Must copy the associations, or later store will effect both the
original and the copy


 

fullCheckNoBecome

Keep array at least 1/4 free for decent hash behavior


 

grow

Grow the elements array and reinsert the old elements


 

growNoBecome


 

keyAt:

May be overridden by subclasses so that fixCollisions will work


 

methodArray


 

rehash

Smalltalk rehash.


 

rehashWithoutBecome


 

removeDangerouslyKey:ifAbsent:

This is not really dangerous. But if normal removal
were done WHILE a MethodDict were being used, the
system might crash. So instead we make a copy, then do
this operation (which is NOT dangerous in a copy that is
not being used), and then use the copy after the removal.


 

scanFor:

Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or zero if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements.


 

swap:with:

May be overridden by subclasses so that fixCollisions will work


  removing top  
 

removeKey:ifAbsent:

The interpreter might be using this MethodDict while
this method is running! Therefore we perform the removal
in a copy, and then atomically become that copy


 

removeKeyNoBecome:

The interpreter might be using this MethodDict while
this method is running! Therefore we perform the removal
in a copy, and then return the copy for subsequent installation


class methods
  instance creation top  
 

new

change the default size to be a bit bigger to help reduce the number of #grows while filing in


 

new:

Create a Dictionary large enough to hold nElements without growing.
Note that the basic size must be a power of 2.
It is VITAL (see grow) that size gets doubled if nElements is a power of 2