The Trunk: Collections-ar.268.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ar.268.mcz

commits-2
Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.268.mcz

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

Name: Collections-ar.268
Author: ar
Time: 31 December 2009, 8:00:38 am
UUID: d7d8920f-95b8-bd48-80d1-ccca70274fb6
Ancestors: Collections-ul.267

Enhancements to Collection>>do:displayingProgress:. The new version has two additional features: It allows the provision of a block argument for the label instead of a string, i.e.,

Smalltalk allClasses
    do:[:aClass| (Delay forMilliseconds: 1) wait]
    displayingProgress:[:aClass| 'Processing ', aClass name]

The second addition is an update limit that ensures that we're not spending our time in display updates. When the update limit is zero, we will update every round through the iteration, see:

(Smalltalk allClasses)
    do:[:aClass| (Delay forMilliseconds: 1) wait]
    displayingProgress:[:aClass| 'Processing ', aClass name]
    every: 0.

whereas with non-zero argument we only do this every n msecs:

(Smalltalk allClasses)
    do:[:aClass| (Delay forMilliseconds: 1) wait]
    displayingProgress:[:aClass| 'Processing ', aClass name]
    every: 200.

The default update limit is 20ms which should be a pretty good general choice.


=============== Diff against Collections-ul.267 ===============

Item was changed:
  ----- Method: Collection>>do:displayingProgress: (in category 'enumerating') -----
+ do: aBlock displayingProgress: aStringOrBlock
+ "Enumerate aBlock displaying progress information.
+ If the argument is a string, use a static label for the process.
+ If the argument is a block, evaluate it with the element to retrieve the label.
+ Smalltalk allClasses
+ do:[:aClass| (Delay forMilliseconds: 1) wait]
+ displayingProgress: 'Processing...'.
+ Smalltalk allClasses
+ do:[:aClass| (Delay forMilliseconds: 1) wait]
+ displayingProgress:[:aClass| 'Processing ', aClass name].
+ "
+ ^self do: aBlock displayingProgress: aStringOrBlock every: 20!
- do: aBlock displayingProgress: aString
-
- aString
- displayProgressAt: Sensor cursorPoint
- from: 0 to: self size
- during:
- [:bar |
- self inject: 1 into:
- [:index :each |
- bar value: index.
- aBlock value: each.
- index + 1]]!

Item was added:
+ ----- Method: Collection>>do:displayingProgress:every: (in category 'enumerating') -----
+ do: aBlock displayingProgress: aStringOrBlock every: msecs
+ "Enumerate aBlock displaying progress information.
+ If the argument is a string, use a static label for the process.
+ If the argument is a block, evaluate it with the element to retrieve the label.
+ The msecs argument ensures that updates happen at most every msecs.
+ Example:
+ Smalltalk allClasses
+ do:[:aClass| (Delay forMilliseconds: 1) wait]
+ displayingProgress:[:aClass| 'Processing ', aClass name]
+ every: 0.
+ Smalltalk allClasses
+ do:[:aClass| (Delay forMilliseconds: 1) wait]
+ displayingProgress:[:aClass| 'Processing ', aClass name]
+ every: 100.
+ "
+ | count size labelBlock oldLabel newLabel lastUpdate |
+ labelBlock := aStringOrBlock isString
+ ifTrue:[[:item| aStringOrBlock]]
+ ifFalse:[aStringOrBlock].
+ count := 0.
+ size := self size.
+ '' displayProgressAt: Sensor cursorPoint from: 0 to: size during:[:bar |
+ self do:[:each|
+ "Special handling for initial progress"
+ (count = 0 or:[count = size]) ifTrue:[
+ bar value: count.
+ ProgressNotification signal: '' extra: (oldLabel := labelBlock value: each).
+ lastUpdate := Time millisecondClockValue.
+ ].
+ aBlock value: each.
+ count := count + 1.
+ (Time millisecondsSince: lastUpdate) >= msecs ifTrue:[
+ bar value: count.
+ oldLabel = (newLabel := labelBlock value: each) ifFalse:[
+ ProgressNotification signal: '' extra: (oldLabel := newLabel).
+ ].
+ lastUpdate := Time millisecondClockValue.
+ ].
+ ]]!

Item was removed:
- ----- Method: SequenceableCollection>>do:displayingProgress: (in category 'enumerating') -----
- do: aBlock displayingProgress: aString
- aString
- displayProgressAt: Sensor cursorPoint
- from: 0 to: self size
- during:
- [:bar |
- self withIndexDo:
- [:each :i |
- bar value: i.
- aBlock value: each]]!