GH #504: Infinite loop (or performance issue) writing using MultiByteEncoding (O(n^2) -> O(n))