Unique all characters?
philippe.marschall at gmail.com
Mon Jan 28 19:08:46 UTC 2008
2008/1/28, Eliot Miranda <eliot.miranda at gmail.com>:
> Hi All,
> 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
> value: anInteger
> "Answer the Character whose value is anInteger."
> | theCharacter existingInstanceOrNil |
> anInteger <= 255 ifTrue:
> [^CharacterTable at: anInteger + 1].
> theCharacter := self basicNew setValue: anInteger.
> ^(existingInstanceOrNil := LargeCodeCharacters like: theCharacter)
> ifNil: [LargeCodeCharacters add: theCharacter]
> ifNotNil: [existingInstanceOrNil]
> 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).
Lord no, please no more Weak* collections. That was one of the major
performance fixes we did in Seaside, kicking Weak* collections. They
don't scale, they kill you in production.
More information about the Squeak-dev