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

commits at source.squeak.org commits at source.squeak.org
Thu Feb 24 13:46:40 UTC 2011


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

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

Name: Collections-ul.427
Author: ul
Time: 24 February 2011, 2:42:16.909 pm
UUID: 40a987b8-4024-9e45-bdb9-ac0b0b888ad2
Ancestors: Collections-ul.426

OrderedCollection tweaks:
- optimized (bytecode + stack usage) #addFirst: and #addLast:
- removed the #asInteger send from #at:put:, because no other operations use it
- recategorized and commented #reset and #resetTo:

=============== Diff against Collections-ul.426 ===============

Item was changed:
  ----- Method: OrderedCollection>>addFirst: (in category 'adding') -----
  addFirst: newObject 
  	"Add newObject to the beginning of the receiver. Answer newObject."
  
+ 	firstIndex = 1 ifTrue: [ self makeRoomAtFirst ].
+ 	^array at: (firstIndex := firstIndex - 1) put: newObject!
- 	firstIndex = 1 ifTrue: [self makeRoomAtFirst].
- 	firstIndex := firstIndex - 1.
- 	array at: firstIndex put: newObject.
- 	^ newObject!

Item was changed:
  ----- Method: OrderedCollection>>addLast: (in category 'adding') -----
  addLast: newObject 
  	"Add newObject to the end of the receiver. Answer newObject."
  
+ 	array size = lastIndex ifTrue: [ self makeRoomAtLast ].
+ 	^array at: (lastIndex := lastIndex + 1) put: newObject!
- 	lastIndex = array size ifTrue: [self makeRoomAtLast].
- 	lastIndex := lastIndex + 1.
- 	array at: lastIndex put: newObject.
- 	^ newObject!

Item was changed:
  ----- Method: OrderedCollection>>at:put: (in category 'accessing') -----
  at: anInteger put: anObject 
  	"Put anObject at element index anInteger. at:put: cannot be used to
  	append, front or back, to an ordered collection; it is used by a
  	knowledgeable client to replace an element."
  
+ 	(anInteger < 1 or: [anInteger + firstIndex - 1 > lastIndex])
- 	| index |
- 	index := anInteger asInteger.
- 	(index < 1 or: [index + firstIndex - 1 > lastIndex])
  		ifTrue: [self errorNoSuchElement]
+ 		ifFalse: [^array at: anInteger + firstIndex - 1 put: anObject]!
- 		ifFalse: [^array at: index + firstIndex - 1 put: anObject]!

Item was changed:
+ ----- Method: OrderedCollection>>reset (in category 'removing') -----
- ----- Method: OrderedCollection>>reset (in category 'private') -----
  reset
+ 	"Quickly remove all elements. The objects will be still referenced, but will not be 	accessible."
+ 	
- 
  	self resetTo: 1!

Item was changed:
+ ----- Method: OrderedCollection>>resetTo: (in category 'removing') -----
- ----- Method: OrderedCollection>>resetTo: (in category 'private') -----
  resetTo: index
+ 	"Quickly remove all elements. The objects will be still referenced, but will not be 	accessible. Also make sure that the first object will be inserted at index. Choosing the 	right value has had great impact on performance, but it's neglible with the current 	implementation, so it's better to use #reset instead in most cases."
+ 	
  	firstIndex := index.
  	lastIndex := firstIndex - 1!



More information about the Packages mailing list