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

commits at source.squeak.org commits at source.squeak.org
Sun Nov 7 03:59:57 UTC 2010


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

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

Name: Collections-ul.404
Author: ul
Time: 7 November 2010, 4:52:11.401 am
UUID: 2e0defd1-6e46-7243-be6f-b571c6805ae4
Ancestors: Collections-ul.403

- simplified SharedQueue >> #makeRoomAtEnd
- enhanced SharedQueue >> #peek

=============== Diff against Collections-ul.403 ===============

Item was changed:
  ----- Method: SharedQueue>>makeRoomAtEnd (in category 'private') -----
  makeRoomAtEnd
  
+ 	| contentsSize newContentsArray |
- 	| contentsSize |
  	contentsSize := writePosition - readPosition.
+ 	newContentsArray := contentsSize * 2 > contentsArray size
+ 		ifTrue: [ contentsArray class new: contentsArray size * 2 ]
- 	contentsSize * 2 > contentsArray size
- 		ifTrue: [
- 			"grow"
- 			contentsArray := (contentsArray class new: contentsArray size * 2)
- 				replaceFrom: 1
- 				to: contentsSize
- 				with: contentsArray
- 				startingAt: readPosition;
- 				yourself ]
  		ifFalse: [
  			(contentsArray size > 10 and: [ contentsSize * 4 <= contentsArray size ])
+ 				ifTrue: [ contentsArray class new: (contentsSize * 2 max: 10) ]
+ 				ifFalse: [ contentsArray ] ].
+ 	newContentsArray
+ 		replaceFrom: 1
+ 		to: contentsSize
+ 		with: contentsArray
+ 		startingAt: readPosition.
+ 	contentsArray == newContentsArray 
+ 		ifFalse: [ contentsArray := newContentsArray ]
+ 		ifTrue: [ contentsArray from: contentsSize + 1 to: contentsArray size put: nil ].
- 				ifTrue: [
- 					"shrink"
- 					contentsArray := (contentsArray class new: (contentsSize * 2 max: 10))
- 						replaceFrom: 1
- 						to: contentsSize
- 						with: contentsArray
- 						startingAt: readPosition;
- 						yourself ]
- 				ifFalse: [
- 					"just move the elements to the front"
- 					contentsArray
- 						replaceFrom: 1
- 						to: contentsSize
- 						with: contentsArray
- 						startingAt: readPosition.
- 					contentsArray
- 						from: contentsSize + 1
- 						to: contentsArray size
- 						put: nil ] ].
  	readPosition := 1.
  	writePosition := contentsSize + 1!

Item was changed:
  ----- Method: SharedQueue>>peek (in category 'accessing') -----
  peek
  	"Answer the object that was sent through the receiver first and has not 
  	yet been received by anyone but do not remove it from the receiver. If 
  	no object has been sent, return nil"
  
+ 	readSynch isSignaled ifFalse: [ ^nil ].
+ 	^accessProtect critical: [
+ 		readPosition >= writePosition ifFalse: [
+ 			contentsArray at: readPosition ] ]!
- 	^accessProtect
- 		critical: [
- 			| value |
- 			readPosition >= writePosition
- 					ifTrue: [readPosition := 1.
- 							writePosition := 1.
- 							value := nil]
- 					ifFalse: [value := contentsArray at: readPosition].
- 			value].!




More information about the Squeak-dev mailing list