Hi Sven,

Thanks for the quick reply.


On Tue, 28 Aug 2018 at 13:17, Sven Van Caekenberghe <[email protected]> wrote:
>
> Hi Alistair,
>
> Thanks for the feedback, but consider:
>
> count := 10000.
> str := 'test-äöü'.
> [
>    count timesRepeat: [
>        ZnCharacterEncoder utf8 encodeString: str
> ] ] timeToRunWithoutGC.
>
> => 8
>
> #newForEncoding: is indeed slow as it has to look through all known encoders, 
> which also involves a subclasses search, which is a PITA.
>
> ZnCharacterEncoder class>>#utf8 actually uses a cached default instance (see 
> ZnUTF8Encoder class>>#default). As this is the most used encoder, with no 
> customization options, it makes sense. For example, #utf8Encoded and 
> #utf8Decoded use this instance.
>
> However, some (byte, utf16, utf32) encoders do have state (endianness, 
> strictness, ...), so global caching could be an issue.
>
> Users of the encoders are free to cache their own instances.
>
> I am not (yet) convinced that a global cache is needed.

Somehow I missed the existence of ZnCharacterEncoder class>>#utf8.
That certainly covers the cases I'm think of, so I'll just use it.

Thanks again,
Alistair

Reply via email to