Unique all characters?
Eliot Miranda
eliot.miranda at gmail.com
Mon Jan 28 18:23:57 UTC 2008
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
following:
Character addClassVarNamed: 'LargeCodeCharacters'.
*Character class methods for class initialization*
*initialize*
[*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).
Just a thought...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080128/15222dfa/attachment.htm
More information about the Squeak-dev
mailing list
|