[squeak-dev] The Inbox: Collections-jar.924.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Feb 7 08:42:11 UTC 2021


A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-jar.924.mcz

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

Name: Collections-jar.924
Author: jar
Time: 7 February 2021, 9:42:07.649004 am
UUID: 073b26bc-8e5e-ba41-9aac-9d424bbe6848
Ancestors: Collections-dtl.923

Fixes SharedQueue >> nextOrNilSuchThat bug to pass the existing test

=============== Diff against Collections-dtl.923 ===============

Item was changed:
  ----- Method: SharedQueue>>nextOrNilSuchThat: (in category 'accessing') -----
  nextOrNilSuchThat: aBlock
  	"Answer the next object that satisfies aBlock, skipping any intermediate objects.
  	If no object has been sent, answer <nil> and leave me intact.
  	NOTA BENE:  aBlock MUST NOT contain a non-local return (^)."
  
  	^accessProtect critical: [
  		| value readPos |
  		value := nil.
  		readPos := readPosition.
  		[ readPos < writePosition and: [ value isNil ] ] whileTrue: [
  			value := contentsArray at: readPos.
  			readPos := readPos + 1.
  			(aBlock value: value)
  				ifFalse: [ value := nil ]
  				ifTrue: [
  					readSynch waitIfLocked: [ ^nil ]. "We found the value, but someone else booked it."
+ 					readPos-1 to: readPosition+1 by: -1 do: [ :j | contentsArray at: j put: (contentsArray at: j-1) ].
+ 					contentsArray at: readPosition put: nil.
+ 					readPosition := readPosition+1 ] ].
- 					readPosition to: readPos - 1 do: [ :j | contentsArray at: j put: nil ].
- 					readPosition := readPos ] ].
  		value ].
  "===
  q := SharedQueue new.
  1 to: 10 do: [ :i | q nextPut: i].
  c := OrderedCollection new.
  [
  	v := q nextOrNilSuchThat: [ :e | e odd].
  	v notNil
  ] whileTrue: [
  	c add: {v. q size}
  ].
  {c. q} explore
  ==="!



More information about the Squeak-dev mailing list