summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-05-24 20:04:03 -0300
committerMårten Nordheim <marten.nordheim@qt.io>2024-05-25 15:14:20 +0000
commit56568fdee66ee30fd6d0afdd2a60c9355aba759c (patch)
tree700573e7a776cda3931a044e354dc3846af78f13
parent6c7738a7d61178cbc809f441bdcd8345c43ba1ca (diff)
QByteArray::setNum: use assign() instead of clear()+append()
clear() will shed any stored capacity, so that's a waste for the few people who actually use setNum(). The majority use it from number(), in which case the clear() is superfluous anyway. And append() does an extra strlen() check, which we don't need. This considerably reduces the size of both QByteArray::setNum() in a GCC LTO build (though the compiler chose to not inline assign()). Moreover, it now does inline setNum() in the number() functions and in a lot more places (searching for "qulltoa2" in the disassembly finds it in QFileSystemEngine::id, for example). Change-Id: If3345151ddf84c43a4f1fffd17d28f2fc79aa072 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/text/qbytearray.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 09c103a0b94..c140a6aec8b 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -4209,9 +4209,7 @@ QByteArray &QByteArray::setNum(qlonglong n, int base)
p = qulltoa2(buff + buffsize, qulonglong(n), base);
}
- clear();
- append(p, buffsize - (p - buff));
- return *this;
+ return assign(QByteArrayView{p, buff + buffsize});
}
/*!
@@ -4226,9 +4224,7 @@ QByteArray &QByteArray::setNum(qulonglong n, int base)
char buff[buffsize];
char *p = qulltoa2(buff + buffsize, n, base);
- clear();
- append(p, buffsize - (p - buff));
- return *this;
+ return assign(QByteArrayView{p, buff + buffsize});
}
/*!