Unique all characters?
eliot.miranda at gmail.com
Mon Jan 28 18:23:57 UTC 2008
having just stumbled across the fact that only characters with codes
from 0 to 255 are unique I wondered whether anyone has considered doing the
Character addClassVarNamed: 'LargeCodeCharacters'.
*Character class methods for class initialization*
[*LargeCodeCharacters* := *WeakSet* new
*Character class methods for instance creation*
*"Answer the Character whose value is anInteger."*
| *theCharacter* *existingInstanceOrNil* |
*anInteger* <= 255 ifTrue:
[*^**CharacterTable* at: *anInteger* + 1].
*theCharacter* *:=* *self* basicNew setValue: *anInteger*.
*^*(*existingInstanceOrNil* *:=* *LargeCodeCharacters* like: *
ifNil: [*LargeCodeCharacters* add: *theCharacter*]
Yes this has the potential to create a lot of space overhead, but only for
artificial codes that enumerate over all characters. I suspect that for
most cases the actual set of active characters would be quite small.
(Alternatives that are indexed by integers might also work well, e.g. a flat
WeakValueDictionary that used a WeakArray for its values).
Just a thought...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev