Thanks Doru.  That looks really useful.  I've added it to the rule rectification tips...
https://pharo.fogbugz.com/default.asp?12184

cheers -ben

Tudor Girba wrote:
You already have it:

'' join: #('abc' 'def' 'ghi')

Doru


On Sat, Nov 16, 2013 at 7:09 PM, <[email protected]> wrote:

  
Code Critic rule Optimization > String concatenation instead of streams
says:

"Check for string concatenation inside some iteration message. Since
string concatenation is O(n^2), it is better to use streaming since it is
O(n) - assuming that n is large enough. As a general principal avoid ,
since the receiver is copied. Therefore chaining , messages will lead to
multiple useless copies of the receiver."

That is,
   String streamContents: [:s |
       #('abc' 'def' 'ghi')  do: [:each | s nextPutAll: each asString]]

should be used instead of...
   'abc' , 'def' , 'ghi'.

However the first clutters the code.  What about something like...
   { 'abc' . 'def' . 'ghi' } asStreamString
where
   Collection>>asStreamString
       ^ String streamContents: [:s | self do: [:each | s nextPutAll: each
asString]]

cheers -ben


    


  

Reply via email to