X Tutup
Skip to content

GRUtf8CodecStream Latin1ToUtf8Encodings is a Global ... should be class var #3

@dalehenrich

Description

@dalehenrich
GRUtf8CodecStream
nextPutAll: aString
    "conversion of smaller string is faster if not using the changeClassTo: trick"
    binary
        ifTrue: [ stream nextPutAll: aString asString ]
        ifFalse: [ aString size > 8
                        ifTrue: [ stream nextPutAll: (aString encodeAsUTF8 changeClassTo: String) ]
                        ifFalse: [ | enc  str | enc := aString encodeAsUTF8. 
                                     str := String new: enc size.
                                    1 to: enc size do: [:idx | str at: idx put: (Character value: (enc at: idx)) ].
                                    stream nextPutAll: str ] ]


GRUtf8CodecStream
nextPut: aCharacter
    "old implementation is very slow !!"
"   self nextPutAll: (String with: aCharacter)"
    | codePoint |
    codePoint := aCharacter codePoint.
    codePoint > 127
        ifTrue: [ 
            codePoint > 255
                ifTrue: [ | enc str |
                        enc := (String with: aCharacter) encodeAsUTF8. 
                         str := String new: enc size.
                        1 to: enc size do: [:idx | str at: idx put: (Character value: (enc at: idx)) ].
                        stream nextPutAll: str ]
                ifFalse: [ stream nextPutAll: (Latin1ToUtf8Encodings at: codePoint + 1) ] ]
        ifFalse: [ stream nextPut: aCharacter ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup