Colin Putney uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.494.mcz ==================== Summary ==================== Name: Collections-ul.494 Author: ul Time: 25 October 2012, 1:56:50.407 am UUID: 1b62455b-152d-4ffc-8072-5b6086cb26a8 Ancestors: Collections-cwp.493 - more straightforward String >> #numArgs implementation (early returns, less branches) - added an optimized version of #canBeToken to ByteSymbol - removed the sentence about uppercase first letter from String >> #numArgs, because it wasn't true even in 2004 =============== Diff against Collections-fbs.490 =============== Item was added: + ----- Method: ByteString>>canBeToken (in category 'testing') ----- + canBeToken + "Optimized version for the common case." + + ^ (self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) = 0 + ! Item was added: + ----- Method: ByteSymbol>>canBeToken (in category 'testing') ----- + canBeToken + "Optimized version for the common case." + + | index | + index := 0. + [ (index := self findSubstring: '~' in: self startingAt: index + 1 matchTable: Tokenish) = 0 ] + whileFalse: [ + (self at: index) == $_ ifFalse: [ ^false ] ]. + ^true + ! Item was added: + ----- Method: String>>canBeToken (in category 'testing') ----- + canBeToken + "Extracted from #numArgs to allow specialization by subclasses" + + ^ self allSatisfy: [:c | c tokenish]! Item was changed: ----- Method: String>>numArgs (in category 'accessing') ----- numArgs + "Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. It is intended mostly for the assistance of spelling correction." - "Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction." + | firstChar numColons start ix | + self size = 0 ifTrue: [ ^-1 ]. - | firstChar numColons excess start ix | - self size = 0 ifTrue: [^ -1]. firstChar := self at: 1. + firstChar isSpecial ifTrue: [ + 2 to: self size do: [ :i | (self at: i) isSpecial ifFalse: [ ^-1 ] ]. + ^1 ]. + firstChar isLetter ifFalse: [ ^-1 ]. + self canBeToken ifFalse: [ ^-1 ]. + "Fast colon count" + numColons := 0. + start := 1. + [ (ix := self indexOf: $: startingAt: start) > 0 ] whileTrue: [ + numColons := numColons + 1. + start := ix + 1]. + (numColons > 0 and: [ self last ~= $: ]) ifTrue: [ ^-1 ]. + ^numColons! - (firstChar isLetter or: [firstChar = $:]) ifTrue: - ["Fast reject if any chars are non-alphanumeric - NOTE: fast only for Byte things - Broken for Wide" - Scanner prefAllowUnderscoreSelectors ifFalse: - [self class isBytes - ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]] - ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]]]. - "Fast colon count" - numColons := 0. start := 1. - [(ix := self indexOf: $: startingAt: start) > 0] - whileTrue: - [numColons := numColons + 1. - start := ix + 1]. - numColons = 0 ifTrue: [^ 0]. - firstChar = $: - ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"] - ifFalse: [excess := 0]. - self last = $: - ifTrue: [^ numColons - excess] - ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]]. - firstChar isSpecial ifTrue: - [self size = 1 ifTrue: [^ 1]. - 2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]]. - ^ 1]. - ^ -1.! Item was added: + ----- Method: Symbol>>canBeToken (in category 'testing') ----- + canBeToken + "Since definition of #tokenish depends on a preference, we want to make sure + that underscores are always considered tokenish. This is so that selectors created + when the preference was turned on don't suddenly become invalid when the + preference is turned off." + + ^ self allSatisfy: [:c | c = $_ or: [c tokenish]]! |
Free forum by Nabble | Edit this page |