The Trunk: Collections-nice.320.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-nice.320.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.320.mcz

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

Name: Collections-nice.320
Author: nice
Time: 26 February 2010, 12:58:09.834 am
UUID: 5736e518-e074-104f-9b5e-75c544d37e3b
Ancestors: Collections-nice.319

Let findAnySubStr:startingAt: use inject:into:
Minor speed up, better code, no outer temp assignment

=============== Diff against Collections-nice.319 ===============

Item was changed:
  ----- Method: String>>findAnySubStr:startingAt: (in category 'accessing') -----
  findAnySubStr: delimiters startingAt: start
  "Answer the index of the character within the receiver, starting at start, that begins a substring matching one of the delimiters.  delimiters is an Array of Strings (Characters are permitted also).  If the receiver does not contain any of the delimiters, answer size + 1."
 
+ ^delimiters inject: 1 + self size into: [:min :delim |
+ "delim may be a char, a string of length 1, or a substring"
+ | ind |
+ ind := delim isCharacter
+ ifTrue: [self indexOf: delim
- | min |
- min := self size + 1.
- delimiters do: [:delim | | ind | "May be a char, a string of length 1, or a substring"
- delim isCharacter
- ifTrue: [ind := self indexOfSubCollection: (String with: delim)
  startingAt: start ifAbsent: [min]]
+ ifFalse: [self indexOfSubCollection: delim
- ifFalse: [ind := self indexOfSubCollection: delim
  startingAt: start ifAbsent: [min]].
+ min min: ind]!
- min := min min: ind].
- ^ min!