A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-kks.798.mcz ==================== Summary ==================== Name: Collections-kks.798 Author: kks Time: 6 July 2018, 3:20:06.403752 pm UUID: 151011b4-ef92-409b-9078-bdd1be01ce87 Ancestors: Collections-cmm.797 Attempt to retain as much styling as possible while filing in text from streams where the runs may fall short or extend beyond the string. Based on Bob's suggestions at http://lists.squeakfoundation.org/pipermail/squeak-dev/2018-July/199530.html =============== Diff against Collections-cmm.797 =============== Item was changed: ----- Method: Text>>setString:setRunsChecking: (in category 'private') ----- setString: aString setRunsChecking: aRunArray + | stringSize runsSize | - "Check runs and do the best you can to make them fit..." - string := aString. - "check the runs" - aRunArray ifNil: [^ aString asText]. (aRunArray isKindOf: RunArray) ifFalse: [^ aString asText]. - aRunArray runs size = aRunArray values size ifFalse: [^ aString asText]. - aRunArray size = aString size ifFalse: [^ aString asText]. + "Check runs and do the best you can to make them fit..." + runsSize := aRunArray runs size. + runsSize = aRunArray values size ifFalse: [^ aString asText]. "raise error here?" + stringSize := string size. + runs := stringSize = runsSize + ifTrue: [aRunArray] + ifFalse: [ stringSize > runsSize + ifTrue: [aRunArray addLast: {} times: stringSize - runsSize] + ifFalse: [aRunArray copyFrom: 1 to: stringSize]].! - runs := aRunArray.! |
This seems like a good thing to do - add the logic in setString:setRunsChecking:
to ensure that the RunArray size matches the actual string size. I think that the ifNil: check should go back in, because a nil RunArray is probably a common case, and the nil check is very fast. But that draws my eye to something else. Looking and the method history, this check has been in place since at least 1997: (aRunArray isKindOf: RunArray) ifFalse: [^ aString asText]. This looks like some leftover check from early development, and I cannot imagine that there would be any need for it today. So maybe we can get rid of the isKindOf: and put the ifNil: check back in. Dave On Fri, Jul 06, 2018 at 09:50:22AM +0000, [hidden email] wrote: > A new version of Collections was added to project The Inbox: > http://source.squeak.org/inbox/Collections-kks.798.mcz > > ==================== Summary ==================== > > Name: Collections-kks.798 > Author: kks > Time: 6 July 2018, 3:20:06.403752 pm > UUID: 151011b4-ef92-409b-9078-bdd1be01ce87 > Ancestors: Collections-cmm.797 > > Attempt to retain as much styling as possible while filing in text from streams where the runs may fall short or extend beyond the string. > > Based on Bob's suggestions at http://lists.squeakfoundation.org/pipermail/squeak-dev/2018-July/199530.html > > =============== Diff against Collections-cmm.797 =============== > > Item was changed: > ----- Method: Text>>setString:setRunsChecking: (in category 'private') ----- > setString: aString setRunsChecking: aRunArray > + | stringSize runsSize | > - "Check runs and do the best you can to make them fit..." > - > string := aString. > - "check the runs" > - aRunArray ifNil: [^ aString asText]. > (aRunArray isKindOf: RunArray) ifFalse: [^ aString asText]. > - aRunArray runs size = aRunArray values size ifFalse: [^ aString asText]. > - aRunArray size = aString size ifFalse: [^ aString asText]. > > + "Check runs and do the best you can to make them fit..." > + runsSize := aRunArray runs size. > + runsSize = aRunArray values size ifFalse: [^ aString asText]. "raise error here?" > + stringSize := string size. > + runs := stringSize = runsSize > + ifTrue: [aRunArray] > + ifFalse: [ stringSize > runsSize > + ifTrue: [aRunArray addLast: {} times: stringSize - runsSize] > + ifFalse: [aRunArray copyFrom: 1 to: stringSize]].! > - runs := aRunArray.! > > |
Thanks for your insight, Dave. I will send a new patch with these changes.
Regards .. Subbu On Saturday 07 July 2018 11:18 PM, David T. Lewis wrote: > This seems like a good thing to do - add the logic in setString:setRunsChecking: > to ensure that the RunArray size matches the actual string size. > > I think that the ifNil: check should go back in, because a nil RunArray is > probably a common case, and the nil check is very fast. > > But that draws my eye to something else. Looking and the method history, this > check has been in place since at least 1997: > > (aRunArray isKindOf: RunArray) ifFalse: [^ aString asText]. > > This looks like some leftover check from early development, and I cannot > imagine that there would be any need for it today. So maybe we can get rid > of the isKindOf: and put the ifNil: check back in. > > Dave > > > On Fri, Jul 06, 2018 at 09:50:22AM +0000, [hidden email] wrote: >> A new version of Collections was added to project The Inbox: >> http://source.squeak.org/inbox/Collections-kks.798.mcz >> >> ==================== Summary ==================== >> >> Name: Collections-kks.798 >> Author: kks >> Time: 6 July 2018, 3:20:06.403752 pm >> UUID: 151011b4-ef92-409b-9078-bdd1be01ce87 >> Ancestors: Collections-cmm.797 >> >> Attempt to retain as much styling as possible while filing in text from streams where the runs may fall short or extend beyond the string. >> >> Based on Bob's suggestions at http://lists.squeakfoundation.org/pipermail/squeak-dev/2018-July/199530.html >> >> =============== Diff against Collections-cmm.797 =============== >> >> Item was changed: >> ----- Method: Text>>setString:setRunsChecking: (in category 'private') ----- >> setString: aString setRunsChecking: aRunArray >> + | stringSize runsSize | >> - "Check runs and do the best you can to make them fit..." >> - >> string := aString. >> - "check the runs" >> - aRunArray ifNil: [^ aString asText]. >> (aRunArray isKindOf: RunArray) ifFalse: [^ aString asText]. >> - aRunArray runs size = aRunArray values size ifFalse: [^ aString asText]. >> - aRunArray size = aString size ifFalse: [^ aString asText]. >> >> + "Check runs and do the best you can to make them fit..." >> + runsSize := aRunArray runs size. >> + runsSize = aRunArray values size ifFalse: [^ aString asText]. "raise error here?" >> + stringSize := string size. >> + runs := stringSize = runsSize >> + ifTrue: [aRunArray] >> + ifFalse: [ stringSize > runsSize >> + ifTrue: [aRunArray addLast: {} times: stringSize - runsSize] >> + ifFalse: [aRunArray copyFrom: 1 to: stringSize]].! >> - runs := aRunArray.! >> >> > |
Free forum by Nabble | Edit this page |