[squeak-dev] The Trunk: Collections-ul.426.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Feb 22 15:29:10 UTC 2011


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

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

Name: Collections-ul.426
Author: ul
Time: 22 February 2011, 4:28:33.228 pm
UUID: 1ef01c01-6a9e-784f-a56d-9dd8f6182024
Ancestors: Collections-ul.425

- fix: make sure that PositionableStream >> #positionOfSubCollection:ifAbsent: restores the position of the stream even if the subcollection is not found
- also removed some unreachable code and refactored the method

=============== Diff against Collections-ul.425 ===============

Item was changed:
  ----- Method: PositionableStream>>positionOfSubCollection:ifAbsent: (in category 'positioning') -----
  positionOfSubCollection: subCollection ifAbsent: exceptionBlock
  	"Return a position such that that element at the new position equals the first element of sub, and the next elements equal the rest of the elements of sub. Begin the search at the current position.
  	If no such match is found, answer the result of evaluating argument, exceptionBlock."
  
  	| pattern startPosition currentPosition |
+ 	pattern := subCollection readStream.
- 	pattern := ReadStream on: subCollection.
  	startPosition := self position.
+ 	[ pattern atEnd or: [ self atEnd ] ] whileFalse: [
+ 		self next = pattern next ifFalse: [
+ 			self position: self position - pattern position + 1.
+ 			pattern reset ] ].
- 	[pattern atEnd] whileFalse: 
- 		[self atEnd ifTrue: [^exceptionBlock value].
- 		self next = pattern next
- 			ifFalse: [
- 				self position: self position-pattern position+1.
- 				pattern reset]].
  	currentPosition := self position.
  	self position: startPosition.
+ 	pattern atEnd ifTrue: [ ^currentPosition + 1 - subCollection size ].
+ 	^exceptionBlock value!
- 	^pattern atEnd
- 		ifTrue: [currentPosition + 1 - subCollection size]
- 		ifFalse: [exceptionBlock value]!




More information about the Squeak-dev mailing list