[squeak-dev] The Inbox: Files-dtl.184.mcz
Levente Uzonyi
leves at caesar.elte.hu
Fri Oct 25 13:22:32 UTC 2019
Hi Dave,
While error handling seems to be a straigforward fix, the reason why
#adoptInstance: is used there is to:
1. be as quick as possible
2. avoid garbage creation (to achieve 1)
An error handler works against those goals.
Using pure #asByteArray, which is even more straightforward, would be a better
choice, as it would be faster and would create no or less garbage than an
error handler. If you have a look at the method's history, you'll see that
was used before #adoptInstance:.
There is also the complementary method, #ascii, which does the same
conversion but to ByteString instead of to ByteArray. I suppose that
method also doesn't work on V3.
IIRC, the V3 VMs support primitive 115 (#primitiveChangeClassTo:). If they
do, I'd rather change #adoptInstance:'s fallback code to try
#primitiveChangeClassTo: (preferably only on V3 to avoid any side
effects). That way other users of #adoptInstance: could work on V3.
Levente
On Fri, 25 Oct 2019, commits at source.squeak.org wrote:
> David T. Lewis uploaded a new version of Files to project The Inbox:
> http://source.squeak.org/inbox/Files-dtl.184.mcz
>
> ==================== Summary ====================
>
> Name: Files-dtl.184
> Author: dtl
> Time: 24 October 2019, 10:15:34.856587 pm
> UUID: cfa02841-644b-49cb-b3f2-a0eb1b36707b
> Ancestors: Files-pre.183
>
> Provide error handling for #adoptInstance in StandardFileStream>>binary to provide pre-Spur behavior when running on a V3 image. Prior to Spur, class ByteArray cannot adopt an instance of ByteString, so use #asByteArray instead.
>
> Resolves the only remaining difference for package Files when running on either Spur or V3 images. The packages with significant Spur/V3 differences (excluding unit tests) are now Collections, Compiler, Kernel, and System. See www.squeaksource.com/TrunkUpdateStreamV3 for verification.
>
> =============== Diff against Files-pre.183 ===============
>
> Item was changed:
> ----- Method: StandardFileStream>>binary (in category 'properties-setting') -----
> binary
> "Read and/or write in binary mode."
> buffer1
> ifNil: [ buffer1 := ByteArray new: 1 ]
> + ifNotNil: [ [ ByteArray adoptInstance: buffer1 ]
> + on: Error "V3 image"
> + do: [ buffer1 := ByteArray new: 1 ] ].
> + collection ifNotNil: [ [ ByteArray adoptInstance: collection ]
> + on: Error
> + do: [ collection := collection asByteArray ] ].
> - ifNotNil: [ ByteArray adoptInstance: buffer1 ].
> - collection ifNotNil: [ ByteArray adoptInstance: collection ].
> lastWritten ifNotNil:
> [ lastWritten isCharacter ifTrue: [ lastWritten := lastWritten asInteger ] ]!
More information about the Squeak-dev
mailing list
|