message String>>fromString:
Richard A. O'Keefe
ok at cs.otago.ac.nz
Wed Jun 12 02:45:11 UTC 2002
Kamil Kukura <kamk at volny.cz> wrote:
I found in String>>fromString:
"Answer an instance of me that is a copy of the argument, aString."
Well, if "me" is not pure String but something derived, the above is not
true.
(DerivedString fromString: 'hello world') className "gives String"
Fortunately ('hello world' as: DerivedString) works.
The method body reads
^aString copyFrom: 1 to: aString size
which boils down to
(aString species new: aString size)
replaceFrom: 1 to: aString size with: aString startingAt: 1
If the method body were to read
^(self new: aString size)
replaceFrom: 1 to: aString size with: aString startingAt: 1
then this would agree with the method comment AND be slightly faster.
More information about the Squeak-dev
mailing list
|