[squeak-dev] The Trunk: Collections-nice.158.mcz

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

[squeak-dev] The Trunk: Collections-nice.158.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.158.mcz

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

Name: Collections-nice.158
Author: nice
Time: 5 October 2009, 10:23:31 am
UUID: 27baf0fe-4d19-0e4e-841a-1f3abfcf7901
Ancestors: Collections-nice.157

Apply patch from http://bugs.squeak.org/view.php?id=6535
keyBlock and sortBlock are lost when creating a collection of the same species.

Unlike http://bugs.squeak.org/view.php?id=6535 initial solution, avoid defining a basicShallowCopy.
This requires using postCopy paradigm as pre-requisite.

If new methods are added before old methods are modified, this patch should load without problem in MC, else I will revert...

=============== Diff against Collections-nice.157 ===============

Item was added:
+ ----- Method: Set>>copyEmpty (in category 'copying') -----
+ copyEmpty
+ "Answer an empty copy of this collection"
+
+ "Note: this code could be moved to super"
+
+ ^self species new!

Item was added:
+ ----- Method: Set>>select: (in category 'enumerating') -----
+ select: aBlock
+ "Use copyEmpty instead of self species new to give subclasses a chance to initialize additional inst vars."
+
+ "Note: this code could be moved to super"
+
+ | newCollection |
+ newCollection := self copyEmpty.
+ self do: [:each | (aBlock value: each) ifTrue: [newCollection add: each]].
+ ^newCollection!

Item was added:
+ ----- Method: PluggableDictionary>>copyEmpty (in category 'copying') -----
+ copyEmpty
+ ^super copyEmpty
+ hashBlock: hashBlock;
+ equalBlock: equalBlock!

Item was changed:
  ----- Method: Dictionary>>select: (in category 'enumerating') -----
  select: aBlock
  "Evaluate aBlock with each of my values as the argument. Collect into a new dictionary, only those associations for which aBlock evaluates to true."
 
  | newCollection |
+ newCollection := self copyEmpty.
- newCollection := self species new.
  self associationsDo: [ :each |
  (aBlock value: each value) ifTrue: [
  newCollection add: each copy ] ].
  ^newCollection!

Item was added:
+ ----- Method: PluggableSet>>copyEmpty (in category 'copying') -----
+ copyEmpty
+ ^super copyEmpty
+ hashBlock: hashBlock;
+ equalBlock: equalBlock!

Item was added:
+ ----- Method: KeyedSet>>copyEmpty (in category 'copying') -----
+ copyEmpty
+ ^super copyEmpty
+ keyBlock: keyBlock!

Item was changed:
  ----- Method: OrderedCollection>>copyFrom:to: (in category 'copying') -----
  copyFrom: startIndex to: endIndex
  "Answer a copy of the receiver that contains elements from position
  startIndex to endIndex."
 
+ ^self shallowCopy postCopyFrom: startIndex to: endIndex!
- | targetCollection |
- endIndex < startIndex ifTrue: [^self species new: 0].
- targetCollection := self species new: endIndex + 1 - startIndex.
- startIndex to: endIndex do: [:index | targetCollection addLast: (self at: index)].
- ^ targetCollection!

Item was added:
+ ----- Method: OrderedCollection>>postCopyFrom:to: (in category 'copying') -----
+ postCopyFrom: startIndex to: endIndex
+ "finish copying the array in a certain range."
+
+ endIndex < startIndex ifFalse: [
+ "Because actual size of the array may be greater than used size,
+ postCopyFrom:to: may fail to fail and answer an incorrect result
+ if this sanity check were not applied"
+ (startIndex between: 1 and: self size) ifFalse: [^self error: 'startIndex is out of bounds'].
+ (endIndex between: 1 and: self size) ifFalse: [^self error: 'endIndex is out of bounds']].
+
+ "Add a protection that lacks in Array>>postcopy"
+ array := array copyFrom: startIndex + firstIndex - 1 to: (endIndex max: startIndex - 1) + firstIndex - 1.
+ firstIndex := 1.
+ lastIndex := array size!


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] The Trunk: Collections-nice.158.mcz

Nicolas Cellier
This fail loading because Collections-nice.157 is a pre-requisite
I will try to upload an update.mcm

2009/10/5  <[hidden email]>:

> Nicolas Cellier uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-nice.158.mcz
>
> ==================== Summary ====================
>
> Name: Collections-nice.158
> Author: nice
> Time: 5 October 2009, 10:23:31 am
> UUID: 27baf0fe-4d19-0e4e-841a-1f3abfcf7901
> Ancestors: Collections-nice.157
>
> Apply patch from http://bugs.squeak.org/view.php?id=6535
> keyBlock and sortBlock are lost when creating a collection of the same species.
>
> Unlike http://bugs.squeak.org/view.php?id=6535 initial solution, avoid defining a basicShallowCopy.
> This requires using postCopy paradigm as pre-requisite.
>
> If new methods are added before old methods are modified, this patch should load without problem in MC, else I will revert...
>
> =============== Diff against Collections-nice.157 ===============
>
> Item was added:
> + ----- Method: Set>>copyEmpty (in category 'copying') -----
> + copyEmpty
> +       "Answer an empty copy of this collection"
> +
> +       "Note: this code could be moved to super"
> +
> +       ^self species new!
>
> Item was added:
> + ----- Method: Set>>select: (in category 'enumerating') -----
> + select: aBlock
> +       "Use copyEmpty instead of self species new to give subclasses a chance to initialize additional inst vars."
> +
> +       "Note: this code could be moved to super"
> +
> +       | newCollection |
> +       newCollection := self copyEmpty.
> +       self do: [:each | (aBlock value: each) ifTrue: [newCollection add: each]].
> +       ^newCollection!
>
> Item was added:
> + ----- Method: PluggableDictionary>>copyEmpty (in category 'copying') -----
> + copyEmpty
> +       ^super copyEmpty
> +               hashBlock: hashBlock;
> +               equalBlock: equalBlock!
>
> Item was changed:
>  ----- Method: Dictionary>>select: (in category 'enumerating') -----
>  select: aBlock
>        "Evaluate aBlock with each of my values as the argument. Collect into a new dictionary, only those associations for which aBlock evaluates to true."
>
>        | newCollection |
> +       newCollection := self copyEmpty.
> -       newCollection := self species new.
>        self associationsDo: [ :each |
>                (aBlock value: each value) ifTrue: [
>                        newCollection add: each copy ] ].
>        ^newCollection!
>
> Item was added:
> + ----- Method: PluggableSet>>copyEmpty (in category 'copying') -----
> + copyEmpty
> +       ^super copyEmpty
> +               hashBlock: hashBlock;
> +               equalBlock: equalBlock!
>
> Item was added:
> + ----- Method: KeyedSet>>copyEmpty (in category 'copying') -----
> + copyEmpty
> +       ^super copyEmpty
> +               keyBlock: keyBlock!
>
> Item was changed:
>  ----- Method: OrderedCollection>>copyFrom:to: (in category 'copying') -----
>  copyFrom: startIndex to: endIndex
>        "Answer a copy of the receiver that contains elements from position
>        startIndex to endIndex."
>
> +       ^self shallowCopy postCopyFrom: startIndex to: endIndex!
> -       | targetCollection |
> -       endIndex < startIndex ifTrue: [^self species new: 0].
> -       targetCollection := self species new: endIndex + 1 - startIndex.
> -       startIndex to: endIndex do: [:index | targetCollection addLast: (self at: index)].
> -       ^ targetCollection!
>
> Item was added:
> + ----- Method: OrderedCollection>>postCopyFrom:to: (in category 'copying') -----
> + postCopyFrom: startIndex to: endIndex
> +       "finish copying the array in a certain range."
> +
> +       endIndex < startIndex ifFalse: [
> +               "Because actual size of the array may be greater than used size,
> +               postCopyFrom:to: may fail to fail and answer an incorrect result
> +               if this sanity check were not applied"
> +               (startIndex between: 1 and: self size) ifFalse: [^self error: 'startIndex is out of bounds'].
> +               (endIndex between: 1 and: self size) ifFalse: [^self error: 'endIndex is out of bounds']].
> +
> +       "Add a protection that lacks in Array>>postcopy"
> +       array := array copyFrom: startIndex + firstIndex - 1 to: (endIndex max: startIndex - 1) + firstIndex - 1.
> +       firstIndex := 1.
> +       lastIndex := array size!
>
>
>