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

commits at source.squeak.org commits at source.squeak.org
Sat Apr 11 21:21:13 UTC 2015


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

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

Name: Collections-ul.616
Author: ul
Time: 11 April 2015, 11:12:16.588 pm
UUID: ff292158-e8cd-4d21-aae6-c15135dd707f
Ancestors: Collections-bf.615

Optimized Interval >> #sum, OrderedCollection >> #at: and OrderedCollection >> #at:put:.

=============== Diff against Collections-bf.615 ===============

Item was changed:
  ----- Method: Interval>>sum (in category 'accessing') -----
  sum
+ 	"Optimized version. Use the sum(n * i - k, i=a..b) = -1/2 * (a - b - 1) * (n * (a + b) - 2 * k) equation with a = 1, n = step, b = self size and k = step - start."
- 	"Optimized version. Use the sum(n*i - k, i=a..b) = -1/2*(a - b - 1)*(n * (a + b) - 2 * k) equation with a = 1, n = step, b = self size."
  
  	| b |
  	b := self size.
+ 	^b * ((b - 1) * step + (start * 2)) / 2!
- 	^b * ((b + 1) * step - (step - start * 2)) / 2!

Item was changed:
  ----- Method: OrderedCollection>>at: (in category 'accessing') -----
  at: anInteger 
  	"Answer my element at index anInteger. at: is used by a knowledgeable
  	client to access an existing element"
  
+ 	| index |
+ 	1 <= anInteger ifFalse: [ self errorNoSuchElement ].
+ 	(index := anInteger + firstIndex - 1) <= lastIndex ifFalse: [ self errorNoSuchElement ].
+ 	^array at: index!
- 	(anInteger < 1 or: [anInteger + firstIndex - 1 > lastIndex])
- 		ifTrue: [self errorNoSuchElement]
- 		ifFalse: [^ array at: anInteger + firstIndex - 1]!

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."
  
+ 	| index |
+ 	1 <= anInteger ifFalse: [ self errorNoSuchElement ].
+ 	(index := anInteger + firstIndex - 1) <= lastIndex ifFalse: [ self errorNoSuchElement ].
+ 	^array at: index put: anObject!
- 	(anInteger < 1 or: [anInteger + firstIndex - 1 > lastIndex])
- 		ifTrue: [self errorNoSuchElement]
- 		ifFalse: [^array at: anInteger + firstIndex - 1 put: anObject]!



More information about the Squeak-dev mailing list