<div dir="ltr">No idea...<br>Presumably fast up some lookup?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/9/4 H. Hirzel <span dir="ltr"><<a href="mailto:hannes.hirzel@gmail.com" target="_blank">hannes.hirzel@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">What is the aim of the OneCharacterSymbols class?<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, 4 Sep 2013 00:21:42.547 0000, <a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a><br>
<<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> wrote:<br>
> A new version of Collections was added to project The Inbox:<br>
> <a href="http://source.squeak.org/inbox/Collections-nice.530.mcz" target="_blank">http://source.squeak.org/inbox/Collections-nice.530.mcz</a><br>
><br>
> ==================== Summary ====================<br>
><br>
> Name: Collections-nice.530<br>
> Author: nice<br>
> Time: 4 September 2013, 2:21:28.852 am<br>
> UUID: d732aa23-1c77-4c1e-abc0-d8d4506b7f9f<br>
> Ancestors: Collections-ul.529<br>
><br>
> Fix this:<br>
> self assert: (allSymbols select: [:s | s = '+']) size = 1.<br>
><br>
> 1) It is un-necessary to enumerate the 1-char symbols, they already are in<br>
> SymbolTable (the first time they were created via #findIntern: or by virtue<br>
> of last #rehash) !<br>
><br>
> 2) We can use a WeekArray rather than an Array because there is no point in<br>
> keeping a reference to unused 1-char symbols.<br>
><br>
> Maybe we should get rid of OneCharacterSymbols class var, but I didn't<br>
> dare...<br>
><br>
> =============== Diff against Collections-ul.529 ===============<br>
><br>
> Item was changed:<br>
> ----- Method: Symbol class>>allSymbols (in category 'access') -----<br>
> allSymbols<br>
> "Answer all interned symbols"<br>
> ^Array streamContents:[:s|<br>
> s nextPutAll: NewSymbols.<br>
> - s nextPutAll: OneCharacterSymbols.<br>
> s nextPutAll: SymbolTable.<br>
> ].<br>
> !<br>
><br>
> Item was changed:<br>
> ----- Method: Symbol class>>initialize (in category 'class<br>
> initialization') -----<br>
> initialize<br>
><br>
> "Symbol initialize"<br>
><br>
> Symbol rehash.<br>
> + OneCharacterSymbols := WeakArray new: 256.<br>
> + (0 to: 255) do: [ :byte | byte asCharacter asSymbol].<br>
> - OneCharacterSymbols := nil.<br>
> - OneCharacterSymbols := (1 to: 256) collect: [ :i | (i - 1) asCharacter<br>
> asSymbol].<br>
> Smalltalk addToShutDownList: self.<br>
> !<br>
><br>
> Item was changed:<br>
> ----- Method: Symbol class>>internCharacter: (in category 'instance<br>
> creation') -----<br>
> internCharacter: aCharacter<br>
> aCharacter asciiValue > 256 ifTrue:[^self intern: aCharacter asString].<br>
> + ^(OneCharacterSymbols at: aCharacter asciiValue + 1) ifNil:<br>
> [OneCharacterSymbols at: aCharacter asciiValue + 1 put: (self intern:<br>
> aCharacter asString)]<br>
> - OneCharacterSymbols ifNil: [^self intern: aCharacter asString].<br>
> - ^OneCharacterSymbols at: aCharacter asciiValue + 1<br>
> !<br>
><br>
> Item was changed:<br>
> ----- Method: Symbol class>>selectorsContaining: (in category 'access')<br>
> -----<br>
> selectorsContaining: aString<br>
> "Answer a list of selectors that contain aString within them.<br>
> Case-insensitive. Does return symbols that begin with a capital letter."<br>
><br>
> | size selectorList ascii |<br>
><br>
> selectorList := OrderedCollection new.<br>
> (size := aString size) = 0 ifTrue: [^selectorList].<br>
><br>
> aString size = 1 ifTrue:<br>
> [<br>
> ascii := aString first asciiValue.<br>
> + ascii < 128 ifTrue: [(OneCharacterSymbols at: ascii+1) ifNotNil: [:s |<br>
> selectorList add: s]]<br>
> - ascii < 128 ifTrue: [selectorList add: (OneCharacterSymbols at:<br>
> ascii+1)]<br>
> ].<br>
><br>
> (aString first isLetter or: [aString first isDigit]) ifFalse:<br>
> [<br>
> aString size = 2 ifTrue:<br>
> [Symbol hasInterned: aString ifTrue:<br>
> [:s | selectorList add: s]].<br>
> ^selectorList<br>
> ].<br>
><br>
> selectorList := selectorList copyFrom: 2 to: selectorList size.<br>
><br>
> self allSymbolTablesDo: [:each |<br>
> each size >= size ifTrue:<br>
> [(each findSubstring: aString in: each startingAt: 1<br>
> matchTable: CaseInsensitiveOrder) > 0<br>
> ifTrue: [selectorList add: each]]].<br>
><br>
> ^selectorList reject: [:each | "reject non-selectors, but keep ones that<br>
> begin with an uppercase"<br>
> each numArgs < 0 and: [each asString withFirstCharacterDownshifted<br>
> numArgs < 0]].<br>
><br>
> "Symbol selectorsContaining: 'scon'"!<br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>