See: https://forum.dlang.org/post/[email protected]
In the implementation of std.string.tr the main loop is:
foreach (dchar c; str)
meaning char and wchar strings are getting decoded. This leads to problems as reported on the n.g. link.
The correct way to implement it is to just leave it in the encoding of `str`. This should result in a significant speed improvement.
This leaves open what to do if `from` and `to` contain invalid UTF sequences if the conversion of them is necessary. The most pragmatic solution is to reject `from` and `to` arguments to `tr` that are not of the same UTF encoding as `str`.
Comment #1 by robert.schadek — 2024-12-01T16:35:27Z