[Pkg] The Trunk: Collections-ul.515.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Apr 27 20:23:43 UTC 2013


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.515.mcz

==================== Summary ====================

Name: Collections-ul.515
Author: ul
Time: 27 April 2013, 10:20:14.97 pm
UUID: fcc2326f-4e72-46f2-b4b7-352227d94b21
Ancestors: Collections-fbs.514

- a slightly faster (~20%) and simpler (IMHO) implementation of String >> #numArgs

=============== Diff against Collections-fbs.514 ===============

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."
  
+ 	| numColons index size |
+ 	(size := self size) = 0 ifTrue: [ ^-1 ].
+ 	index := 1.
+ 	(self at: index) isSpecial ifTrue: [
+ 		2 to: size do: [ :i | (self at: i) isSpecial ifFalse: [ ^-1 ] ].
- 	| firstChar numColons 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 ].
  	self canBeToken ifFalse: [ ^-1 ].
  	"Fast colon count"
  	numColons := 0.
+ 	[ 
+ 		(self at: index) isLetter ifFalse: [ ^-1 ].
+ 		(index := (self indexOf: $: startingAt: index) + 1) > 1 ifFalse: [ 
+ 			numColons = 0 ifTrue: [ ^0 ].
+ 			^-1 ].
- 	start := 1.
- 	[firstChar isLetter ifFalse: [ ^-1 ].
- 	(ix := self indexOf: $: startingAt: start) > 0 ] whileTrue: [
  		numColons := numColons + 1.
+ 		index <= size ] whileTrue.
- 		(start := ix + 1) > self size ifFalse: [firstChar := self at: start]].
- 	(numColons > 0 and: [ self last ~= $: ]) ifTrue: [ ^-1 ].
  	^numColons!



More information about the Packages mailing list