MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / assign_utf8_in_place

Function assign_utf8_in_place

app/src/DataModel/Frame.h:895–919  ·  view source on GitHub ↗

* @brief Writes UTF-8 bytes into a QString, reusing the destination buffer for ASCII payloads. The * widen runs branchless (OR-accumulating the high bit instead of an in-loop early return) so * it auto-vectorizes; a single non-ASCII byte then redoes the rare frame via * QString::fromUtf8. */

Source from the content-addressed store, hash-verified

893 * QString::fromUtf8.
894 */
895SS_FORCE_INLINE void assign_utf8_in_place(QString& dst, QByteArrayView src)
896{
897 const char* p = src.data();
898 const qsizetype n = src.size();
899
900 Q_ASSERT(n >= 0);
901
902 if (!(dst.isDetached() && dst.capacity() >= n)) {
903 dst = QString();
904 dst.reserve(qMax<qsizetype>(n, 8));
905 }
906
907 dst.resize(n);
908 QChar* out = dst.data();
909
910 uchar nonAscii = 0;
911 for (qsizetype i = 0; i < n; ++i) {
912 const uchar c = static_cast<uchar>(p[i]);
913 nonAscii |= c;
914 out[i] = QChar(static_cast<char16_t>(c));
915 }
916
917 if (nonAscii & 0x80) [[unlikely]]
918 dst = QString::fromUtf8(p, n);
919}
920
921/**
922 * @brief Copies per-frame volatile state (source id + dataset values) into a structure-matched dst.

Callers 2

applyDatasetValueSpanMethod · 0.85

Calls 4

dataMethod · 0.45
sizeMethod · 0.45
capacityMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected