From: Olivier Goffart Date: Sat, 23 Sep 2017 12:09:19 +0000 (+0200) Subject: c_utf8_from_locale: optimize the UTF8 case on Linux X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~701^2~47 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d100f9ac674bbed61b5e35fcbb87f1d9fb2e44b0;p=nextcloud-desktop.git c_utf8_from_locale: optimize the UTF8 case on Linux Avoid converting to a QString as an intermediate step --- diff --git a/src/csync/std/c_utf8.cpp b/src/csync/std/c_utf8.cpp index f4f5d1ac2..2f862b5ce 100644 --- a/src/csync/std/c_utf8.cpp +++ b/src/csync/std/c_utf8.cpp @@ -59,7 +59,15 @@ QByteArray c_utf8_from_locale(const mbchar_t *wstr) } return dst; #else - QTextDecoder dec(QTextCodec::codecForLocale()); + auto codec = QTextCodec::codecForLocale(); +#ifndef __APPLE__ + if (codec->mibEnum() == 106) { // UTF-8 + // Optimisation for UTF-8: no need to convert to QString. + // We still need to do it for mac because of normalization + return QByteArray(wstr); + } +#endif + QTextDecoder dec(codec); QString s = dec.toUnicode(wstr, qstrlen(wstr)); if (s.isEmpty() || dec.hasFailure()) { /* Conversion error: since we can't report error from this function, just return the original