The Trunk: Collections-ar.166.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-ar.166.mcz

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

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

Name: Collections-ar.166
Author: ar
Time: 13 October 2009, 7:35:06 am
UUID: 9abba6f5-43ec-b047-bd87-bf240bbac59d
Ancestors: Collections-ul.163, Collections-ul.164, Collections-ul.165

Merging Collections-ul.164, Collections-ul.165:

- removed Matrix >> #shallowCopy. The contents array is already copied in #postCopy, don't have to do it twice. This may break code which assumes that #shallowCopy copies the contents array which is a really bad assumption.
- also removed empty category "copying" from Interval
- faster and simpler String >> #format:, String >> #withBlanksTrimmed

=============== Diff against Collections-ul.163 ===============

Item was changed:
  ----- Method: String>>evaluateExpression:parameters: (in category 'private') -----
  evaluateExpression: aString parameters: aCollection
  "private - evaluate the expression aString with  
  aCollection as the parameters and answer the  
  evaluation result as an string"
  | index |
+ index := Integer readFrom: aString readStream base: 10.
- index := ('0' , aString) asNumber.
 
  index isZero
  ifTrue: [^ '[invalid subscript: {1}]' format: {aString}].
 
  index > aCollection size
  ifTrue: [^ '[subscript is out of bounds: {1}]' format: {aString}].
 
  ^ (aCollection at: index) asString!

Item was changed:
  ----- Method: String>>format: (in category 'formatting') -----
  format: aCollection
  "format the receiver with aCollection  
 
  simplest example:  
  'foo {1} bar' format: {Date today}.
 
  complete example:  
+ '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
- '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.  
  "
+ ^String new: self size streamContents: [ :result |
+ | stream currentChar |
+ stream := self readStream.
+ [ (currentChar := stream next) == nil ] whileFalse: [
- | result stream |
- result := String new writeStream.
- stream := self readStream.
-
- [stream atEnd]
- whileFalse: [| currentChar |
- currentChar := stream next.
  currentChar == ${
+ ifTrue: [
+ result nextPutAll: (
+ self
+ evaluateExpression: (stream upTo: $}) withBlanksTrimmed
+ parameters: aCollection) ]
- ifTrue: [| expression |
- expression := self getEnclosedExpressionFrom: stream.
- result
- nextPutAll: (self evaluateExpression: expression parameters: aCollection)]
  ifFalse: [
  currentChar == $\
+ ifFalse: [ result nextPut: currentChar ]
+ ifTrue: [
+ (currentChar := stream next) ifNotNil: [
+ result nextPut: currentChar ] ] ] ] ]!
- ifTrue: [stream atEnd
- ifFalse: [result nextPut: stream next]]
- ifFalse: [result nextPut: currentChar]]].
-
- ^ result contents!

Item was changed:
  ----- Method: String>>withBlanksTrimmed (in category 'converting') -----
  withBlanksTrimmed
  "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
 
+ | first last |
+ first := self findFirst: [ :c | c isSeparator not ].
+ first = 0 ifTrue: [ ^'' ].  "no non-separator character"
+ last := self findLast: [ :c | c isSeparator not ].
+ (first = 1 and: [ last = self size ]) ifTrue: [ ^self copy ].
+ ^self
- | first result |
- first := self findFirst: [:c | c isSeparator not].
- first = 0 ifTrue: [^ ''].  "no non-separator character"
- result :=  self
  copyFrom: first
+ to: last
- to: (self findLast: [:c | c isSeparator not]).
- result isOctetString ifTrue: [^ result asOctetString] ifFalse: [^ result].
-
- " ' abc  d   ' withBlanksTrimmed"
  !

Item was removed:
- ----- Method: Matrix>>shallowCopy (in category 'copying') -----
- shallowCopy
- ^self class rows: nrows columns: ncols contents: contents shallowCopy!

Item was removed:
- ----- Method: String>>getEnclosedExpressionFrom: (in category 'private') -----
- getEnclosedExpressionFrom: aStream
- "private - get the expression enclosed between '{' and
- '}' and remove all the characters from the stream"
- | result currentChar |
- result := String new writeStream.
-
- [aStream atEnd
- or: [(currentChar := aStream next) == $}]]
- whileFalse: [result nextPut: currentChar].
-
- ^ result contents withBlanksTrimmed!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-ar.166.mcz

Nicolas Cellier
Oh, yes, I hesitated about Matrix >> #shallowCopy, because previous
implementation was just silly...
I again approve the removal of this method, we can afford to break
broken code sometimes...

Nicolas

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

> Andreas Raab uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-ar.166.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ar.166
> Author: ar
> Time: 13 October 2009, 7:35:06 am
> UUID: 9abba6f5-43ec-b047-bd87-bf240bbac59d
> Ancestors: Collections-ul.163, Collections-ul.164, Collections-ul.165
>
> Merging Collections-ul.164, Collections-ul.165:
>
> - removed Matrix >> #shallowCopy. The contents array is already copied in #postCopy, don't have to do it twice. This may break code which assumes that #shallowCopy copies the contents array which is a really bad assumption.
> - also removed empty category "copying" from Interval
> - faster and simpler String >> #format:, String >> #withBlanksTrimmed
>
> =============== Diff against Collections-ul.163 ===============
>
> Item was changed:
>  ----- Method: String>>evaluateExpression:parameters: (in category 'private') -----
>  evaluateExpression: aString parameters: aCollection
>        "private - evaluate the expression aString with
>        aCollection as the parameters and answer the
>        evaluation result as an string"
>        | index |
> +       index := Integer readFrom: aString readStream base: 10.
> -       index := ('0' , aString) asNumber.
>
>        index isZero
>                ifTrue: [^ '[invalid subscript: {1}]' format: {aString}].
>
>        index > aCollection size
>                ifTrue: [^ '[subscript is out of bounds: {1}]' format: {aString}].
>
>        ^ (aCollection at: index) asString!
>
> Item was changed:
>  ----- Method: String>>format: (in category 'formatting') -----
>  format: aCollection
>        "format the receiver with aCollection
>
>        simplest example:
>        'foo {1} bar' format: {Date today}.
>
>        complete example:
> +       '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
> -       '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
>        "
> +       ^String new: self size streamContents: [ :result |
> +               | stream currentChar |
> +               stream := self readStream.
> +               [ (currentChar := stream next) == nil ] whileFalse: [
> -       | result stream |
> -       result := String new writeStream.
> -       stream := self readStream.
> -
> -       [stream atEnd]
> -               whileFalse: [| currentChar |
> -                       currentChar := stream next.
>                        currentChar == ${
> +                               ifTrue: [
> +                                       result nextPutAll: (
> +                                               self
> +                                                       evaluateExpression: (stream upTo: $}) withBlanksTrimmed
> +                                                       parameters: aCollection) ]
> -                               ifTrue: [| expression |
> -                                       expression := self getEnclosedExpressionFrom: stream.
> -                                       result
> -                                               nextPutAll: (self evaluateExpression: expression parameters: aCollection)]
>                                ifFalse: [
>                                        currentChar == $\
> +                                               ifFalse: [ result nextPut: currentChar ]
> +                                               ifTrue: [
> +                                                       (currentChar := stream next) ifNotNil: [
> +                                                               result nextPut: currentChar ] ] ] ] ]!
> -                                               ifTrue: [stream atEnd
> -                                                               ifFalse: [result nextPut: stream next]]
> -                                               ifFalse: [result nextPut: currentChar]]].
> -
> -       ^ result contents!
>
> Item was changed:
>  ----- Method: String>>withBlanksTrimmed (in category 'converting') -----
>  withBlanksTrimmed
>        "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
>
> +       | first last |
> +       first := self findFirst: [ :c | c isSeparator not ].
> +       first = 0 ifTrue: [ ^'' ].  "no non-separator character"
> +       last := self findLast: [ :c | c isSeparator not ].
> +       (first = 1 and: [ last = self size ]) ifTrue: [ ^self copy ].
> +       ^self
> -       | first result |
> -       first := self findFirst: [:c | c isSeparator not].
> -       first = 0 ifTrue: [^ ''].  "no non-separator character"
> -       result :=  self
>                copyFrom: first
> +               to: last
> -               to: (self findLast: [:c | c isSeparator not]).
> -       result isOctetString ifTrue: [^ result asOctetString] ifFalse: [^ result].
> -
> -       " ' abc  d   ' withBlanksTrimmed"
>  !
>
> Item was removed:
> - ----- Method: Matrix>>shallowCopy (in category 'copying') -----
> - shallowCopy
> -       ^self class rows: nrows columns: ncols contents: contents shallowCopy!
>
> Item was removed:
> - ----- Method: String>>getEnclosedExpressionFrom: (in category 'private') -----
> - getEnclosedExpressionFrom: aStream
> -       "private - get the expression enclosed between '{' and
> -       '}' and remove all the characters from the stream"
> -       | result currentChar |
> -       result := String new writeStream.
> -
> -       [aStream atEnd
> -               or: [(currentChar := aStream next) == $}]]
> -               whileFalse: [result nextPut: currentChar].
> -
> -       ^ result contents withBlanksTrimmed!
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-ar.166.mcz

Andreas.Raab
Nicolas Cellier wrote:
> Oh, yes, I hesitated about Matrix >> #shallowCopy, because previous
> implementation was just silly...
> I again approve the removal of this method, we can afford to break
> broken code sometimes...

I must be missing something subtle here. How would this code break? I
looked at it and I didn't see anything problematic with it.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: Re: The Trunk: Collections-ar.166.mcz

Colin Putney

On 14-Oct-09, at 11:00 AM, Andreas Raab wrote:

> Nicolas Cellier wrote:
>> Oh, yes, I hesitated about Matrix >> #shallowCopy, because previous
>> implementation was just silly...
>> I again approve the removal of this method, we can afford to break
>> broken code sometimes...
>
> I must be missing something subtle here. How would this code break?  
> I looked at it and I didn't see anything problematic with it.

I think he meant sender of #shallowCopy that assume it's not shallow.  
"We can afford to break broken code."

Colin

Reply | Threaded
Open this post in threaded view
|

Re: Re: The Trunk: Collections-ar.166.mcz

Nicolas Cellier
Yes, that's what I meant.

2009/10/14 Colin Putney <[hidden email]>:

>
> On 14-Oct-09, at 11:00 AM, Andreas Raab wrote:
>
>> Nicolas Cellier wrote:
>>>
>>> Oh, yes, I hesitated about Matrix >> #shallowCopy, because previous
>>> implementation was just silly...
>>> I again approve the removal of this method, we can afford to break
>>> broken code sometimes...
>>
>> I must be missing something subtle here. How would this code break? I
>> looked at it and I didn't see anything problematic with it.
>
> I think he meant sender of #shallowCopy that assume it's not shallow. "We
> can afford to break broken code."
>
> Colin
>
>