help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] gst-shape


From: Gwenaël Casaccio
Subject: [Help-smalltalk] gst-shape
Date: Mon, 18 Oct 2010 11:42:34 +0200

Hi,

I would like to announce gst-shape git://github.com/MrGwen/gst-shape.git
a refactoring of the class shape, a small example of the power of this new
refactoring:

Before:

    primDump: anObject [
        "Private - Basic code to dump anObject on the stream associated with the
         receiver, without using proxies and the like."

        <category: 'private'>
        | class shape |
        self storeClass: (class := anObject class).
        self register: anObject.
        class isVariable ifTrue: [self nextPutLong: anObject basicSize].
        1 to: class instSize do: [:i | self dump: (anObject instVarAt: i)].
        class isVariable ifFalse: [^self].
        class isPointers
            ifTrue: [^self store: anObject through: [:obj | self dump: obj]].
        shape := class shape.
        shape == #character
            ifTrue: [^self store: anObject through: [:char | stream
nextPut: char]].
        (shape == #byte or: [shape == #int8])
            ifTrue: [^self store: anObject through: [:byte | self
nextPutByte: byte]].
        (shape == #short or: [shape == #ushort])
            ifTrue: [^self store: anObject through: [:short | self
nextPutShort: short]].
        (shape == #int or: [shape == #int])
            ifTrue: [^self store: anObject through: [:int | self
nextPutLong: int]].
        (shape == #int64 or: [shape == #uint64])
            ifTrue: [^self store: anObject through: [:int64 | self
nextPutInt64: int64]].
        shape == #utf32
            ifTrue:
                [^self store: anObject through: [:char | self
nextPutLong: char codePoint]].
        shape == #float
            ifTrue: [^self store: anObject through: [:float | self
nextPutFloat: float]].
        shape == #double
            ifTrue:
                [^self store: anObject through: [:double | self
nextPutFloat: double]].
        self notYetImplemented
    ]

After:
ObjectDumper >>
    primDump: anObject [
        "Private - Basic code to dump anObject on the stream associated with the
         receiver, without using proxies and the like."

        <category: 'private'>
        | class |
        self storeClass: (class := anObject class).
        self register: anObject.
        class isVariable ifTrue: [ self nextPutLong: anObject basicSize ].
        1 to: class instSize do: [ :i | self dump: (anObject instVarAt: i) ].
        class isVariable ifFalse: [ ^ self ].
        ^ class shape dumper: self store: anObject
    ]

The support inside Behavior is not totally finished but it goes on the
right direction.
Gwen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]