The Trunk: Collections-cmm.531.mcz

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

The Trunk: Collections-cmm.531.mcz

commits-2
Chris Muller uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-cmm.531.mcz

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

Name: Collections-cmm.531
Author: cmm
Time: 6 September 2013, 2:26:33.695 pm
UUID: da0031c2-e1d3-4f49-a425-9808728e3f1a
Ancestors: Collections-ul.530

- Remove redundant isVariableBinding override.
- Characters can now be tested for isAscii.
- Dictionary's and Set's made proxy-friendly.
- Remove redundant isLiteral override.
- Allow #asMutator to work for getter or setter selectors.

=============== Diff against Collections-ul.530 ===============

Item was removed:
- ----- Method: Association>>isVariableBinding (in category 'testing') -----
- isVariableBinding
- "Return true if I represent a literal variable binding"
- ^true!

Item was added:
+ ----- Method: Character>>isAscii (in category 'testing') -----
+ isAscii
+ ^ value between: 0 and: 128!

Item was changed:
  ----- Method: Dictionary>>keysSortedSafely (in category 'accessing') -----
  keysSortedSafely
  "Answer a sorted Array containing the receiver's keys."
+ ^ self keys sort:
+ [ : x : y | x compareSafely: y ]!
-
- ^self keys sort: [ :x :y |
- "Should really be use <obj, string, num> compareSafely..."
- ((x isString and: [ y isString ])
- or: [ x isNumber and: [ y isNumber ] ])
- ifTrue: [ x < y ]
- ifFalse: [ x class == y class
- ifTrue: [ x printString < y printString ]
- ifFalse: [ x class name < y class name ] ] ].
- !

Item was changed:
  ----- Method: Dictionary>>scanFor: (in category 'private') -----
  scanFor: anObject
  "Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
 
  | index start |
  index := start := anObject hash \\ array size + 1.
  [
  | element |
+ ((element := array at: index) == nil or: [ anObject = element key ])
- ((element := array at: index) == nil or: [ element key = anObject ])
  ifTrue: [ ^index ].
  (index := index \\ array size + 1) = start ] whileFalse.
  self errorNoFreeSpace!

Item was added:
+ ----- Method: Number>>compareSafely: (in category '*collections') -----
+ compareSafely: aNumber
+ "Override method to compare the receiver with aNumber to determine its position in a human-readable list without unnecessarily agitating proxies."
+ ^ self < aNumber!

Item was added:
+ ----- Method: Object>>compareSafely: (in category '*collections') -----
+ compareSafely: anObject
+ "Compare the receiver to anObject to determine its position in a human-readable list without unnecessarily agitating proxies."
+ ^ self class = anObject class
+ ifTrue: [ self printString < anObject printString ]
+ ifFalse: [ self class name < anObject class name ]!

Item was changed:
  ----- Method: Set>>scanFor: (in category 'private') -----
  scanFor: anObject
  "Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."
 
  | index start |
  index := start := anObject hash \\ array size + 1.
  [
  | element |
+ ((element := array at: index) == nil or: [ anObject = element enclosedSetElement ])
- ((element := array at: index) == nil or: [ element enclosedSetElement = anObject ])
  ifTrue: [ ^index ].
  (index := index \\ array size + 1) = start ] whileFalse.
  self errorNoFreeSpace!

Item was added:
+ ----- Method: String>>asAscii (in category 'converting') -----
+ asAscii
+ ^ self select: [ : each | each isAscii ]!

Item was added:
+ ----- Method: String>>compareSafely: (in category '*collections') -----
+ compareSafely: aString
+ "Compare the receiver to aString in a way that will not agitate proxies."
+ ^ self < aString!

Item was changed:
+ ----- Method: String>>isLiteral (in category 'testing') -----
- ----- Method: String>>isLiteral (in category 'printing') -----
  isLiteral
+ "Answer whether the receiver is a valid Smalltalk literal."
 
+ ^ true!
- ^true!

Item was changed:
  ----- Method: Symbol>>asMutator (in category 'converting') -----
  asMutator
+ "Return a setter message from a getter message. For example, #name asMutator returns #name:"
+ ^ self last = $:
+ ifTrue: [ self ]
+ ifFalse: [ (self copyWith: $:) asSymbol ]!
- "Return a setter message from a getter message. For example,
- #name asMutator returns #name:"
- ^ (self copyWith: $:) asSymbol!

Item was removed:
- ----- Method: Symbol>>isLiteral (in category 'testing') -----
- isLiteral
- "Answer whether the receiver is a valid Smalltalk literal."
-
- ^ true!

Item was added:
+ ----- Method: Symbol>>veryDeepCopy (in category 'copying') -----
+ veryDeepCopy
+ "Overridden for performance."
+ ^ self!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-cmm.531.mcz

Nicolas Cellier
ASCII between 0 and 127 rather than 128 ?


2013/9/6 <[hidden email]>
Chris Muller uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-cmm.531.mcz

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

Name: Collections-cmm.531
Author: cmm
Time: 6 September 2013, 2:26:33.695 pm
UUID: da0031c2-e1d3-4f49-a425-9808728e3f1a
Ancestors: Collections-ul.530

- Remove redundant isVariableBinding override.
- Characters can now be tested for isAscii.
- Dictionary's and Set's made proxy-friendly.
- Remove redundant isLiteral override.
- Allow #asMutator to work for getter or setter selectors.

=============== Diff against Collections-ul.530 ===============

Item was removed:
- ----- Method: Association>>isVariableBinding (in category 'testing') -----
- isVariableBinding
-       "Return true if I represent a literal variable binding"
-       ^true!

Item was added:
+ ----- Method: Character>>isAscii (in category 'testing') -----
+ isAscii
+       ^ value between: 0 and: 128!

Item was changed:
  ----- Method: Dictionary>>keysSortedSafely (in category 'accessing') -----
  keysSortedSafely
        "Answer a sorted Array containing the receiver's keys."
+       ^ self keys sort:
+               [ : x : y | x compareSafely: y ]!
-
-        ^self keys sort: [ :x :y |
-               "Should really be use <obj, string, num> compareSafely..."
-               ((x isString and: [ y isString ])
-                       or: [ x isNumber and: [ y isNumber ] ])
-                       ifTrue: [ x < y ]
-                       ifFalse: [ x class == y class
-                               ifTrue: [ x printString < y printString ]
-                               ifFalse: [ x class name < y class name ] ] ].
- !

Item was changed:
  ----- Method: Dictionary>>scanFor: (in category 'private') -----
  scanFor: anObject
        "Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."

        | index start |
        index := start := anObject hash \\ array size + 1.
        [
                | element |
+               ((element := array at: index) == nil or: [ anObject = element key ])
-               ((element := array at: index) == nil or: [ element key = anObject ])
                        ifTrue: [ ^index ].
                (index := index \\ array size + 1) = start ] whileFalse.
        self errorNoFreeSpace!

Item was added:
+ ----- Method: Number>>compareSafely: (in category '*collections') -----
+ compareSafely: aNumber
+       "Override method to compare the receiver with aNumber to determine its position in a human-readable list without unnecessarily agitating proxies."
+       ^ self < aNumber!

Item was added:
+ ----- Method: Object>>compareSafely: (in category '*collections') -----
+ compareSafely: anObject
+       "Compare the receiver to anObject to determine its position in a human-readable list without unnecessarily agitating proxies."
+       ^ self class = anObject class
+               ifTrue: [ self printString < anObject printString ]
+               ifFalse: [ self class name < anObject class name ]!

Item was changed:
  ----- Method: Set>>scanFor: (in category 'private') -----
  scanFor: anObject
        "Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or raise an error if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements."

        | index start |
        index := start := anObject hash \\ array size + 1.
        [
                | element |
+               ((element := array at: index) == nil or: [ anObject = element enclosedSetElement ])
-               ((element := array at: index) == nil or: [ element enclosedSetElement = anObject ])
                        ifTrue: [ ^index ].
                (index := index \\ array size + 1) = start ] whileFalse.
        self errorNoFreeSpace!

Item was added:
+ ----- Method: String>>asAscii (in category 'converting') -----
+ asAscii
+       ^ self select: [ : each | each isAscii ]!

Item was added:
+ ----- Method: String>>compareSafely: (in category '*collections') -----
+ compareSafely: aString
+       "Compare the receiver to aString in a way that will not agitate proxies."
+       ^ self < aString!

Item was changed:
+ ----- Method: String>>isLiteral (in category 'testing') -----
- ----- Method: String>>isLiteral (in category 'printing') -----
  isLiteral
+       "Answer whether the receiver is a valid Smalltalk literal."

+       ^ true!
-       ^true!

Item was changed:
  ----- Method: Symbol>>asMutator (in category 'converting') -----
  asMutator
+       "Return a setter message from a getter message. For example, #name asMutator returns #name:"
+       ^ self last = $:
+               ifTrue: [ self ]
+               ifFalse: [ (self copyWith: $:) asSymbol ]!
-       "Return a setter message from a getter message. For example,
-       #name asMutator returns #name:"
-       ^ (self copyWith: $:) asSymbol!

Item was removed:
- ----- Method: Symbol>>isLiteral (in category 'testing') -----
- isLiteral
-       "Answer whether the receiver is a valid Smalltalk literal."
-
-       ^ true!

Item was added:
+ ----- Method: Symbol>>veryDeepCopy (in category 'copying') -----
+ veryDeepCopy
+       "Overridden for performance."
+       ^ self!





Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-cmm.531.mcz

Chris Muller-3
Doh!  Fixed.

On Fri, Sep 6, 2013 at 2:40 PM, Nicolas Cellier
<[hidden email]> wrote:

> ASCII between 0 and 127 rather than 128 ?
>
>
> 2013/9/6 <[hidden email]>
>
>> Chris Muller uploaded a new version of Collections to project The Trunk:
>> http://source.squeak.org/trunk/Collections-cmm.531.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-cmm.531
>> Author: cmm
>> Time: 6 September 2013, 2:26:33.695 pm
>> UUID: da0031c2-e1d3-4f49-a425-9808728e3f1a
>> Ancestors: Collections-ul.530
>>
>> - Remove redundant isVariableBinding override.
>> - Characters can now be tested for isAscii.
>> - Dictionary's and Set's made proxy-friendly.
>> - Remove redundant isLiteral override.
>> - Allow #asMutator to work for getter or setter selectors.
>>
>> =============== Diff against Collections-ul.530 ===============
>>
>> Item was removed:
>> - ----- Method: Association>>isVariableBinding (in category 'testing')
>> -----
>> - isVariableBinding
>> -       "Return true if I represent a literal variable binding"
>> -       ^true!
>>
>> Item was added:
>> + ----- Method: Character>>isAscii (in category 'testing') -----
>> + isAscii
>> +       ^ value between: 0 and: 128!
>>
>> Item was changed:
>>   ----- Method: Dictionary>>keysSortedSafely (in category 'accessing')
>> -----
>>   keysSortedSafely
>>         "Answer a sorted Array containing the receiver's keys."
>> +       ^ self keys sort:
>> +               [ : x : y | x compareSafely: y ]!
>> -
>> -        ^self keys sort: [ :x :y |
>> -               "Should really be use <obj, string, num> compareSafely..."
>> -               ((x isString and: [ y isString ])
>> -                       or: [ x isNumber and: [ y isNumber ] ])
>> -                       ifTrue: [ x < y ]
>> -                       ifFalse: [ x class == y class
>> -                               ifTrue: [ x printString < y printString ]
>> -                               ifFalse: [ x class name < y class name ] ]
>> ].
>> - !
>>
>> Item was changed:
>>   ----- Method: Dictionary>>scanFor: (in category 'private') -----
>>   scanFor: anObject
>>         "Scan the key array for the first slot containing either a nil
>> (indicating an empty slot) or an element that matches anObject. Answer the
>> index of that slot or raise an error if no slot is found. This method will
>> be overridden in various subclasses that have different interpretations for
>> matching elements."
>>
>>         | index start |
>>         index := start := anObject hash \\ array size + 1.
>>         [
>>                 | element |
>> +               ((element := array at: index) == nil or: [ anObject =
>> element key ])
>> -               ((element := array at: index) == nil or: [ element key =
>> anObject ])
>>                         ifTrue: [ ^index ].
>>                 (index := index \\ array size + 1) = start ] whileFalse.
>>         self errorNoFreeSpace!
>>
>> Item was added:
>> + ----- Method: Number>>compareSafely: (in category '*collections') -----
>> + compareSafely: aNumber
>> +       "Override method to compare the receiver with aNumber to determine
>> its position in a human-readable list without unnecessarily agitating
>> proxies."
>> +       ^ self < aNumber!
>>
>> Item was added:
>> + ----- Method: Object>>compareSafely: (in category '*collections') -----
>> + compareSafely: anObject
>> +       "Compare the receiver to anObject to determine its position in a
>> human-readable list without unnecessarily agitating proxies."
>> +       ^ self class = anObject class
>> +               ifTrue: [ self printString < anObject printString ]
>> +               ifFalse: [ self class name < anObject class name ]!
>>
>> Item was changed:
>>   ----- Method: Set>>scanFor: (in category 'private') -----
>>   scanFor: anObject
>>         "Scan the key array for the first slot containing either a nil
>> (indicating an empty slot) or an element that matches anObject. Answer the
>> index of that slot or raise an error if no slot is found. This method will
>> be overridden in various subclasses that have different interpretations for
>> matching elements."
>>
>>         | index start |
>>         index := start := anObject hash \\ array size + 1.
>>         [
>>                 | element |
>> +               ((element := array at: index) == nil or: [ anObject =
>> element enclosedSetElement ])
>> -               ((element := array at: index) == nil or: [ element
>> enclosedSetElement = anObject ])
>>                         ifTrue: [ ^index ].
>>                 (index := index \\ array size + 1) = start ] whileFalse.
>>         self errorNoFreeSpace!
>>
>> Item was added:
>> + ----- Method: String>>asAscii (in category 'converting') -----
>> + asAscii
>> +       ^ self select: [ : each | each isAscii ]!
>>
>> Item was added:
>> + ----- Method: String>>compareSafely: (in category '*collections') -----
>> + compareSafely: aString
>> +       "Compare the receiver to aString in a way that will not agitate
>> proxies."
>> +       ^ self < aString!
>>
>> Item was changed:
>> + ----- Method: String>>isLiteral (in category 'testing') -----
>> - ----- Method: String>>isLiteral (in category 'printing') -----
>>   isLiteral
>> +       "Answer whether the receiver is a valid Smalltalk literal."
>>
>> +       ^ true!
>> -       ^true!
>>
>> Item was changed:
>>   ----- Method: Symbol>>asMutator (in category 'converting') -----
>>   asMutator
>> +       "Return a setter message from a getter message. For example, #name
>> asMutator returns #name:"
>> +       ^ self last = $:
>> +               ifTrue: [ self ]
>> +               ifFalse: [ (self copyWith: $:) asSymbol ]!
>> -       "Return a setter message from a getter message. For example,
>> -       #name asMutator returns #name:"
>> -       ^ (self copyWith: $:) asSymbol!
>>
>> Item was removed:
>> - ----- Method: Symbol>>isLiteral (in category 'testing') -----
>> - isLiteral
>> -       "Answer whether the receiver is a valid Smalltalk literal."
>> -
>> -       ^ true!
>>
>> Item was added:
>> + ----- Method: Symbol>>veryDeepCopy (in category 'copying') -----
>> + veryDeepCopy
>> +       "Overridden for performance."
>> +       ^ self!
>>
>>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-cmm.531.mcz

Levente Uzonyi-2
In reply to this post by commits-2
On Fri, 6 Sep 2013, [hidden email] wrote:

> Chris Muller uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-cmm.531.mcz
>
> ==================== Summary ====================
>
> Name: Collections-cmm.531
> Author: cmm
> Time: 6 September 2013, 2:26:33.695 pm
> UUID: da0031c2-e1d3-4f49-a425-9808728e3f1a
> Ancestors: Collections-ul.530
>
> - Remove redundant isVariableBinding override.
> - Characters can now be tested for isAscii.
> - Dictionary's and Set's made proxy-friendly.

What about the other Sets and Dictionaries?

> - Remove redundant isLiteral override.
> - Allow #asMutator to work for getter or setter selectors.
>
> =============== Diff against Collections-ul.530 ===============
>
> Item was added:
> + ----- Method: Number>>compareSafely: (in category '*collections') -----
> + compareSafely: aNumber
> + "Override method to compare the receiver with aNumber to determine its position in a human-readable list without unnecessarily agitating proxies."
> + ^ self < aNumber!

You assume that the argument is a Number, but you don't check if it really
is a Number or not. If it's not, then you must use the implemtation in
Object.

> Item was added:
> + ----- Method: String>>compareSafely: (in category '*collections') -----
> + compareSafely: aString
> + "Compare the receiver to aString in a way that will not agitate proxies."
> + ^ self < aString!

Same as with Number: you must check if the argument is a String or not,
otherwise it's not a "Safe" comparison.
Btw, I wonder if these methods should really be in Collections.


Levente

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-cmm.531.mcz

Chris Muller-3
On Fri, Sep 6, 2013 at 7:56 PM, Levente Uzonyi <[hidden email]> wrote:

> On Fri, 6 Sep 2013, [hidden email] wrote:
>
>> Chris Muller uploaded a new version of Collections to project The Trunk:
>> http://source.squeak.org/trunk/Collections-cmm.531.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-cmm.531
>> Author: cmm
>> Time: 6 September 2013, 2:26:33.695 pm
>> UUID: da0031c2-e1d3-4f49-a425-9808728e3f1a
>> Ancestors: Collections-ul.530
>>
>> - Remove redundant isVariableBinding override.
>> - Characters can now be tested for isAscii.
>> - Dictionary's and Set's made proxy-friendly.
>
>
> What about the other Sets and Dictionaries?

Not sure which ones you're referring to, but I'm just being
conservative -- I haven't had a case to observe a problem to fix for
any other types.

>> - Remove redundant isLiteral override.
>> - Allow #asMutator to work for getter or setter selectors.
>>
>> =============== Diff against Collections-ul.530 ===============
>>
>> Item was added:
>> + ----- Method: Number>>compareSafely: (in category '*collections') -----
>> + compareSafely: aNumber
>> +       "Override method to compare the receiver with aNumber to determine
>> its position in a human-readable list without unnecessarily agitating
>> proxies."
>> +       ^ self < aNumber!
>
>
> You assume that the argument is a Number, but you don't check if it really
> is a Number or not. If it's not, then you must use the implemtation in
> Object.

Unfortunately, this whole thing did not really accomplish what I
wanted because the Proxy could be the argument instead of the
receiver.   Still, this factoring is better than what it was, and it
at least helps for Proxy's to be able to override #compareSafely:, but
not water tight..   :(

The real solution for me was to override Dictionary>>#inspectorClass
to simply return BasicInspector.  I may want ot turn that into a
preference at some point.


>> Item was added:
>> + ----- Method: String>>compareSafely: (in category '*collections') -----
>> + compareSafely: aString
>> +       "Compare the receiver to aString in a way that will not agitate
>> proxies."
>> +       ^ self < aString!
>
>
> Same as with Number: you must check if the argument is a String or not,
> otherwise it's not a "Safe" comparison.
> Btw, I wonder if these methods should really be in Collections.
>
>
> Levente
>