[squeak-dev] The Inbox: Collections-cmm.1022.mcz

Eliot Miranda eliot.miranda at gmail.com
Mon Nov 21 13:11:23 UTC 2022


Hi Chris,

     why “add: subString copy” and not just “add: subString”? subString’s values are all instantiated locally to subStrings:, don’t escape other than through the result sequence, and are not duplicated.  The send of copy looks to me to have been a misunderstanding on behalf of a prior author.

I’d also love to see the argument be able to be either a string or a character, with two separate loops in ifTrue:ifFalse: gif efficiency, avoiding instantiating a singleton collection if the arg is a character.

_,,,^..^,,,_ (phone)

> On Nov 18, 2022, at 9:14 PM, commits at source.squeak.org wrote:
> 
> Chris Muller uploaded a new version of Collections to project The Inbox:
> http://source.squeak.org/inbox/Collections-cmm.1022.mcz
> 
> ==================== Summary ====================
> 
> Name: Collections-cmm.1022
> Author: cmm
> Time: 18 November 2022, 11:14:01.223447 pm
> UUID: 9a05d251-4f02-43de-94e8-0f077ec51680
> Ancestors: Collections-nice.1021
> 
> Allow empty fields when using #subStrings:.
> 
> =============== Diff against Collections-nice.1021 ===============
> 
> Item was changed:
>  ----- Method: String>>subStrings: (in category 'converting') -----
>  subStrings: separators 
>      "Answer an array containing the substrings in the receiver separated 
>      by the elements of separators."
>      | char result sourceStream subString |
> -    #Collectn.
> -    "Changed 2000/04/08 For ANSI <readableString> protocol."
>      (separators isString or:[separators allSatisfy: [:element | element isCharacter]]) ifFalse:
>          [^ self error: 'separators must be Characters.'].
>      sourceStream := ReadStream on: self.
>      result := OrderedCollection new.
>      subString := String new.
>      [sourceStream atEnd]
>          whileFalse: 
>              [char := sourceStream next.
>              (separators includes: char)
> +                ifTrue: [result add: subString copy.
> +                            subString := String new]
> -                ifTrue: [subString notEmpty
> -                        ifTrue: 
> -                            [result add: subString copy.
> -                            subString := String new]]
>                  ifFalse: [subString := subString , (String with: char)]].
>      subString notEmpty ifTrue: [result add: subString copy].
>      ^ result asArray!
> 
> 


More information about the Squeak-dev mailing list