QmlDesigner: Reduce allocations

We use std::to_chars instead of QByteArray::number. In the normal case
we only allocate once but if the numbers are unusual long we
would allocate two or three times. But this is very very unlikely.

Change-Id: Ieb734d63962d4cc5a1c1da73f4ccb4acd7db2577
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-01-06 13:05:18 +01:00
committed by Tim Jenssen
parent 13fae30e88
commit 4580a3b222

View File

@@ -44,6 +44,9 @@
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
#include <array>
#include <charconv>
namespace QmlDesigner {
namespace Internal {
@@ -711,9 +714,22 @@ PropertyName NodeMetaInfoPrivate::defaultPropertyName() const
return PropertyName("data");
}
static inline TypeName stringIdentifier( const TypeName &type, int maj, int min)
static void addNumber(TypeName &id, int number)
{
return type + QByteArray::number(maj) + '_' + QByteArray::number(min);
char text[std::numeric_limits<int>::digits10 + 1];
auto [end, error] = std::to_chars(std::begin(text), std::end(text), number);
id.append(std::data(text), static_cast<int>(end - std::begin(text)));
}
static TypeName stringIdentifier(const TypeName &type, int majorVersion, int minorVersion)
{
TypeName id = type;
id.reserve(id.size() + 5);
addNumber(id, majorVersion);
id.append('_');
addNumber(id, minorVersion);
return id;
}
NodeMetaInfoPrivate::Pointer NodeMetaInfoPrivate::create(Model *model, const TypeName &type, int major, int minor)