forked from qt-creator/qt-creator
QmlDesigner: Use TypeNameString instead of Utils::SmallString
It increases the small string optimization area. Many of the type names are longer than the SSO area of Utils::SmallString so we use a custom String for types which has a larger SSO area. So there a much less mallocs. This should improve performance a little but but uses a little bit more memory. Change-Id: I6a2225f21fb16afc8379868f3f18f38ae6ad0cd8 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -43,6 +43,8 @@ constexpr std::underlying_type_t<Enumeration> to_underlying(Enumeration enumerat
|
|||||||
return static_cast<std::underlying_type_t<Enumeration>>(enumeration);
|
return static_cast<std::underlying_type_t<Enumeration>>(enumeration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using TypeNameString = Utils::BasicSmallString<63>;
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|
||||||
namespace QmlDesigner::Storage {
|
namespace QmlDesigner::Storage {
|
||||||
@@ -310,7 +312,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString name;
|
TypeNameString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QualifiedImportedType
|
class QualifiedImportedType
|
||||||
@@ -328,7 +330,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString name;
|
TypeNameString name;
|
||||||
Import import;
|
Import import;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -459,7 +461,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString name;
|
TypeNameString name;
|
||||||
EnumeratorDeclarations enumeratorDeclarations;
|
EnumeratorDeclarations enumeratorDeclarations;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -509,7 +511,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString name;
|
Utils::SmallString name;
|
||||||
Utils::SmallString typeName;
|
TypeNameString typeName;
|
||||||
PropertyDeclarationTraits traits = {};
|
PropertyDeclarationTraits traits = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -584,7 +586,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString name;
|
Utils::SmallString name;
|
||||||
Utils::SmallString returnTypeName;
|
TypeNameString returnTypeName;
|
||||||
ParameterDeclarations parameters;
|
ParameterDeclarations parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -806,7 +808,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallString typeName;
|
TypeNameString typeName;
|
||||||
ImportedTypeName prototype;
|
ImportedTypeName prototype;
|
||||||
ExportedTypes exportedTypes;
|
ExportedTypes exportedTypes;
|
||||||
PropertyDeclarations propertyDeclarations;
|
PropertyDeclarations propertyDeclarations;
|
||||||
|
@@ -128,22 +128,21 @@ Storage::ExportedTypes createExports(const QList<QQmlJSScope::Export> &qmlExport
|
|||||||
exportedTypes.reserve(Utils::usize(qmlExports));
|
exportedTypes.reserve(Utils::usize(qmlExports));
|
||||||
|
|
||||||
for (const QQmlJSScope::Export &qmlExport : qmlExports) {
|
for (const QQmlJSScope::Export &qmlExport : qmlExports) {
|
||||||
Utils::SmallString exportedTypeName{qmlExport.type()};
|
TypeNameString exportedTypeName{qmlExport.type()};
|
||||||
exportedTypes.emplace_back(storage.moduleId(Utils::SmallString{qmlExport.package()}),
|
exportedTypes.emplace_back(storage.moduleId(Utils::SmallString{qmlExport.package()}),
|
||||||
std::move(exportedTypeName),
|
std::move(exportedTypeName),
|
||||||
createVersion(qmlExport.version()));
|
createVersion(qmlExport.version()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString cppExportedTypeName{interanalName};
|
TypeNameString cppExportedTypeName{interanalName};
|
||||||
exportedTypes.emplace_back(cppModuleId, cppExportedTypeName);
|
exportedTypes.emplace_back(cppModuleId, cppExportedTypeName);
|
||||||
|
|
||||||
return exportedTypes;
|
return exportedTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString createCppEnumerationExport(Utils::SmallStringView typeName,
|
auto createCppEnumerationExport(Utils::SmallStringView typeName, Utils::SmallStringView enumerationName)
|
||||||
Utils::SmallStringView enumerationName)
|
|
||||||
{
|
{
|
||||||
Utils::SmallString cppExportedTypeName{typeName};
|
TypeNameString cppExportedTypeName{typeName};
|
||||||
cppExportedTypeName += "::";
|
cppExportedTypeName += "::";
|
||||||
cppExportedTypeName += enumerationName;
|
cppExportedTypeName += enumerationName;
|
||||||
|
|
||||||
@@ -194,12 +193,12 @@ struct EnumerationType
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
Utils::SmallString name;
|
Utils::SmallString name;
|
||||||
Utils::SmallString full;
|
TypeNameString full;
|
||||||
};
|
};
|
||||||
|
|
||||||
using EnumerationTypes = std::vector<EnumerationType>;
|
using EnumerationTypes = std::vector<EnumerationType>;
|
||||||
|
|
||||||
Utils::SmallString fullyQualifiedTypeName(const QString &typeName,
|
TypeNameString fullyQualifiedTypeName(const QString &typeName,
|
||||||
const ComponentWithoutNamespaces &componentNameWithoutNamespace)
|
const ComponentWithoutNamespaces &componentNameWithoutNamespace)
|
||||||
{
|
{
|
||||||
if (auto found = componentNameWithoutNamespace.find(typeName);
|
if (auto found = componentNameWithoutNamespace.find(typeName);
|
||||||
@@ -221,7 +220,7 @@ Storage::PropertyDeclarations createProperties(
|
|||||||
if (qmlProperty.typeName().isEmpty())
|
if (qmlProperty.typeName().isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Utils::SmallString propertyTypeName{
|
TypeNameString propertyTypeName{
|
||||||
fullyQualifiedTypeName(qmlProperty.typeName(), componentNameWithoutNamespace)};
|
fullyQualifiedTypeName(qmlProperty.typeName(), componentNameWithoutNamespace)};
|
||||||
|
|
||||||
auto found = find_if(enumerationTypes.begin(), enumerationTypes.end(), [&](auto &entry) {
|
auto found = find_if(enumerationTypes.begin(), enumerationTypes.end(), [&](auto &entry) {
|
||||||
@@ -327,18 +326,18 @@ Storage::EnumerationDeclarations createEnumeration(const QHash<QString, QQmlJSMe
|
|||||||
enumerationDeclarations.reserve(Utils::usize(qmlEnumerations));
|
enumerationDeclarations.reserve(Utils::usize(qmlEnumerations));
|
||||||
|
|
||||||
for (const QQmlJSMetaEnum &qmlEnumeration : qmlEnumerations) {
|
for (const QQmlJSMetaEnum &qmlEnumeration : qmlEnumerations) {
|
||||||
enumerationDeclarations.emplace_back(Utils::SmallString{qmlEnumeration.name()},
|
enumerationDeclarations.emplace_back(TypeNameString{qmlEnumeration.name()},
|
||||||
createEnumerators(qmlEnumeration));
|
createEnumerators(qmlEnumeration));
|
||||||
}
|
}
|
||||||
|
|
||||||
return enumerationDeclarations;
|
return enumerationDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString addEnumerationType(EnumerationTypes &enumerationTypes,
|
auto addEnumerationType(EnumerationTypes &enumerationTypes,
|
||||||
Utils::SmallStringView typeName,
|
Utils::SmallStringView typeName,
|
||||||
Utils::SmallStringView enumerationName)
|
Utils::SmallStringView enumerationName)
|
||||||
{
|
{
|
||||||
auto fullTypeName = Utils::SmallString::join({typeName, "::", enumerationName});
|
auto fullTypeName = TypeNameString::join({typeName, "::", enumerationName});
|
||||||
enumerationTypes.emplace_back(enumerationName, std::move(fullTypeName));
|
enumerationTypes.emplace_back(enumerationName, std::move(fullTypeName));
|
||||||
|
|
||||||
return fullTypeName;
|
return fullTypeName;
|
||||||
@@ -354,7 +353,7 @@ void addEnumerationType(EnumerationTypes &enumerationTypes,
|
|||||||
{
|
{
|
||||||
auto fullTypeName = addEnumerationType(enumerationTypes, typeName, enumerationName);
|
auto fullTypeName = addEnumerationType(enumerationTypes, typeName, enumerationName);
|
||||||
types.emplace_back(fullTypeName,
|
types.emplace_back(fullTypeName,
|
||||||
Storage::ImportedType{Utils::SmallString{}},
|
Storage::ImportedType{TypeNameString{}},
|
||||||
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
|
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
|
||||||
sourceId,
|
sourceId,
|
||||||
createCppEnumerationExports(typeName,
|
createCppEnumerationExports(typeName,
|
||||||
@@ -393,8 +392,8 @@ EnumerationTypes addEnumerationTypes(Storage::Types &types,
|
|||||||
if (aliases.contains(qmlEnumeration.name()))
|
if (aliases.contains(qmlEnumeration.name()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Utils::SmallString enumerationName{qmlEnumeration.name()};
|
TypeNameString enumerationName{qmlEnumeration.name()};
|
||||||
Utils::SmallString enumerationAlias{qmlEnumeration.alias()};
|
TypeNameString enumerationAlias{qmlEnumeration.alias()};
|
||||||
addEnumerationType(enumerationTypes,
|
addEnumerationType(enumerationTypes,
|
||||||
types,
|
types,
|
||||||
typeName,
|
typeName,
|
||||||
@@ -416,13 +415,13 @@ void addType(Storage::Types &types,
|
|||||||
{
|
{
|
||||||
auto [functionsDeclarations, signalDeclarations] = createFunctionAndSignals(
|
auto [functionsDeclarations, signalDeclarations] = createFunctionAndSignals(
|
||||||
component.ownMethods(), componentNameWithoutNamespace);
|
component.ownMethods(), componentNameWithoutNamespace);
|
||||||
Utils::SmallString typeName{component.internalName()};
|
TypeNameString typeName{component.internalName()};
|
||||||
auto enumerations = component.ownEnumerations();
|
auto enumerations = component.ownEnumerations();
|
||||||
auto exports = component.exports();
|
auto exports = component.exports();
|
||||||
|
|
||||||
auto enumerationTypes = addEnumerationTypes(types, typeName, sourceId, cppModuleId, enumerations);
|
auto enumerationTypes = addEnumerationTypes(types, typeName, sourceId, cppModuleId, enumerations);
|
||||||
types.emplace_back(Utils::SmallStringView{typeName},
|
types.emplace_back(Utils::SmallStringView{typeName},
|
||||||
Storage::ImportedType{Utils::SmallString{component.baseTypeName()}},
|
Storage::ImportedType{TypeNameString{component.baseTypeName()}},
|
||||||
createTypeAccessSemantics(component.accessSemantics()),
|
createTypeAccessSemantics(component.accessSemantics()),
|
||||||
sourceId,
|
sourceId,
|
||||||
createExports(exports, typeName, storage, cppModuleId),
|
createExports(exports, typeName, storage, cppModuleId),
|
||||||
|
Reference in New Issue
Block a user