Skip to content

Commit

Permalink
c_utf8_from_locale: optimize the UTF8 case on Linux
Browse files Browse the repository at this point in the history
Avoid converting to a QString as an intermediate step
  • Loading branch information
ogoffart committed Sep 25, 2017
1 parent 3107e63 commit bf2b089
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/csync/std/c_utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf2b089

Please sign in to comment.