Kris
Fast Unicode transcoders. These are particularly sensitive to
minor changes on 32bit x86 devices, because the register set of
those devices is so small. Beware of subtle changes which might
extend the execution-period by as much as 200%. Because of this,
three of the six transcoders might read past the end of input by
one, two, or three bytes before arresting themselves. Note that
support for streaming adds a 15% overhead to the dchar => char
conversion, but has little effect on the others.
These routines were tuned on an Intel P4; other devices may work
more efficiently with a slightly different approach, though this
is likely to be reasonably optimal on AMD x86 CPUs also. These
algorithms would benefit significantly from those extra AMD64
registers. On a 3GHz P4, the dchar/char conversions take around
2500ns to process an array of 1000 ASCII elements. Invoking the
memory manager doubles that period, and quadruples the time for
arrays of 100 elements. Memory allocation can slow down notably
in a multi-threaded environment, so avoid that where possible.
Surrogate-pairs are dealt with in a non-optimal fashion when
transcoding between utf16 and utf8. Such cases are considered
to be boundary-conditions for this module.
There are three common cases where the input may be incomplete,
including each 'widening' case of utf8 => utf16, utf8 => utf32,
and utf16 => utf32. An edge-case is utf16 => utf8, if surrogate
pairs are present. Such cases will throw an exception, unless
streaming-mode is enabled ~ in the latter mode, an additional
integer is returned indicating how many elements of the input
have been consumed. In all cases, a correct slice of the output
is returned.
For details on Unicode processing see: