summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-07-20 17:06:49 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-07-26 20:43:44 +0000
commit5d0542a356be1c47e2f99e6ba38b8e520ca0710c (patch)
tree1e756b3dbb83f211d330106d5203cbfdf95c327d /src/corelib/text/qstring.cpp
parent7ff72d0a0f1f4964e4d4fd250283711fc51db016 (diff)
QString::number(int): Avoid going through qlocale machinery
For increased performance, as measured with the number_qu?longlong QString benchmarks. The results are all good, reducing runtime by anywhere between 40 and 220 nanoseconds. The slowest test previously completing at ~330ns, now completing at ~105ns. Task-number: QTBUG-88484 Change-Id: Ie96e86e57b635bac01389aed531a6d9f087df983 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 99534cb3d1..11caefc8ec 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -7307,7 +7307,16 @@ QString QString::number(qlonglong n, int base)
base = 10;
}
#endif
- return QLocaleData::c()->longLongToString(n, -1, base);
+QT_WARNING_PUSH
+ /* "unary minus operator applied to unsigned type, result still unsigned" */
+QT_WARNING_DISABLE_MSVC(4146)
+ bool negative = n < 0;
+ /*
+ Negating std::numeric_limits<qlonglong>::min() hits undefined behavior, so
+ taking an absolute value has to cast to unsigned to change sign.
+ */
+ return qulltoBasicLatin(negative ? -qulonglong(n) : qulonglong(n), base, negative);
+QT_WARNING_POP
}
/*!
@@ -7321,7 +7330,7 @@ QString QString::number(qulonglong n, int base)
base = 10;
}
#endif
- return QLocaleData::c()->unsLongLongToString(n, -1, base);
+ return qulltoBasicLatin(n, base, false);
}