[squeak-dev] The Inbox: Collections-ul.494.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Oct 25 00:03:18 UTC 2012


A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/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-cwp.493 ===============

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 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 ].
- 	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 ifTrue:
- 		[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]
- 			ifFalse: [numColons]].
- 	firstChar isSpecial ifTrue:
- 		[self size = 1 ifTrue: [^ 1].
- 		2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
- 		^ 1].
- 	^ -1.!



More information about the Squeak-dev mailing list