moc: eradicate all Q_FOREACH loops
... by replacing them with C++11 range-for, or, for loops over .keys() or .uniqueKeys(), with explicit iterator loops. Saves 2300b in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I6e1d4f5e56895dfd74aba21a3d4e913b5825645c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
2c26d519e2
commit
1c470f3af0
|
|
@ -150,16 +150,17 @@ bool Generator::registerableMetaType(const QByteArray &propertyType)
|
|||
#undef STREAM_SMART_POINTER
|
||||
;
|
||||
|
||||
foreach (const QByteArray &smartPointer, smartPointers)
|
||||
for (const QByteArray &smartPointer : smartPointers) {
|
||||
if (propertyType.startsWith(smartPointer + "<") && !propertyType.endsWith("&"))
|
||||
return knownQObjectClasses.contains(propertyType.mid(smartPointer.size() + 1, propertyType.size() - smartPointer.size() - 1 - 1));
|
||||
}
|
||||
|
||||
static const QVector<QByteArray> oneArgTemplates = QVector<QByteArray>()
|
||||
#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE)
|
||||
#undef STREAM_1ARG_TEMPLATE
|
||||
;
|
||||
foreach (const QByteArray &oneArgTemplateType, oneArgTemplates)
|
||||
for (const QByteArray &oneArgTemplateType : oneArgTemplates) {
|
||||
if (propertyType.startsWith(oneArgTemplateType + "<") && propertyType.endsWith(">")) {
|
||||
const int argumentSize = propertyType.size() - oneArgTemplateType.size() - 1
|
||||
// The closing '>'
|
||||
|
|
@ -169,6 +170,7 @@ bool Generator::registerableMetaType(const QByteArray &propertyType)
|
|||
const QByteArray templateArg = propertyType.mid(oneArgTemplateType.size() + 1, argumentSize);
|
||||
return isBuiltinType(templateArg) || registerableMetaType(templateArg);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1202,10 +1204,14 @@ void Generator::generateStaticMetacall()
|
|||
fprintf(out, " case %d:\n", it.key());
|
||||
fprintf(out, " switch (*reinterpret_cast<int*>(_a[1])) {\n");
|
||||
fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
|
||||
foreach (const QByteArray &key, it->uniqueKeys()) {
|
||||
foreach (int argumentID, it->values(key))
|
||||
fprintf(out, " case %d:\n", argumentID);
|
||||
fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", key.constData());
|
||||
auto jt = it->begin();
|
||||
const auto jend = it->end();
|
||||
while (jt != jend) {
|
||||
fprintf(out, " case %d:\n", jt.value());
|
||||
const QByteArray &lastKey = jt.key();
|
||||
++jt;
|
||||
if (jt == jend || jt.key() != lastKey)
|
||||
fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData());
|
||||
}
|
||||
fprintf(out, " }\n");
|
||||
fprintf(out, " break;\n");
|
||||
|
|
@ -1257,7 +1263,7 @@ void Generator::generateStaticMetacall()
|
|||
needElse = true;
|
||||
}
|
||||
|
||||
QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper();
|
||||
const QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper();
|
||||
|
||||
if (!automaticPropertyMetaTypes.isEmpty()) {
|
||||
if (needElse)
|
||||
|
|
@ -1267,10 +1273,14 @@ void Generator::generateStaticMetacall()
|
|||
fprintf(out, "if (_c == QMetaObject::RegisterPropertyMetaType) {\n");
|
||||
fprintf(out, " switch (_id) {\n");
|
||||
fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
|
||||
foreach (const QByteArray &key, automaticPropertyMetaTypes.uniqueKeys()) {
|
||||
foreach (int propertyID, automaticPropertyMetaTypes.values(key))
|
||||
fprintf(out, " case %d:\n", propertyID);
|
||||
fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", key.constData());
|
||||
auto it = automaticPropertyMetaTypes.begin();
|
||||
const auto end = automaticPropertyMetaTypes.end();
|
||||
while (it != end) {
|
||||
fprintf(out, " case %d:\n", it.value());
|
||||
const QByteArray &lastKey = it.key();
|
||||
++it;
|
||||
if (it == end || it.key() != lastKey)
|
||||
fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData());
|
||||
}
|
||||
fprintf(out, " }\n");
|
||||
fprintf(out, " }\n");
|
||||
|
|
@ -1561,8 +1571,8 @@ void Generator::generatePluginMetaData()
|
|||
data.insert(QStringLiteral("MetaData"), cdef->pluginData.metaData.object());
|
||||
|
||||
// Add -M args from the command line:
|
||||
foreach (const QString &key, cdef->pluginData.metaArgs.keys())
|
||||
data.insert(key, cdef->pluginData.metaArgs.value(key));
|
||||
for (auto it = cdef->pluginData.metaArgs.cbegin(), end = cdef->pluginData.metaArgs.cend(); it != end; ++it)
|
||||
data.insert(it.key(), it.value());
|
||||
|
||||
fputs("\nQT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;\n\n"
|
||||
"#ifdef QT_NO_DEBUG\n", out);
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments)
|
|||
{
|
||||
QStringList allArguments;
|
||||
allArguments.reserve(arguments.size());
|
||||
foreach (const QString &argument, arguments) {
|
||||
for (const QString &argument : arguments) {
|
||||
// "@file" doesn't start with a '-' so we can't use QCommandLineParser for it
|
||||
if (argument.startsWith(QLatin1Char('@'))) {
|
||||
QString optionsFile = argument;
|
||||
|
|
@ -299,25 +299,30 @@ int runMoc(int argc, char **argv)
|
|||
if (parser.isSet(forceIncludeOption)) {
|
||||
moc.noInclude = false;
|
||||
autoInclude = false;
|
||||
foreach (const QString &include, parser.values(forceIncludeOption)) {
|
||||
const auto forceIncludes = parser.values(forceIncludeOption);
|
||||
for (const QString &include : forceIncludes) {
|
||||
moc.includeFiles.append(QFile::encodeName(include));
|
||||
defaultInclude = false;
|
||||
}
|
||||
}
|
||||
foreach (const QString &include, parser.values(prependIncludeOption))
|
||||
const auto prependIncludes = parser.values(prependIncludeOption);
|
||||
for (const QString &include : prependIncludes)
|
||||
moc.includeFiles.prepend(QFile::encodeName(include));
|
||||
if (parser.isSet(pathPrefixOption))
|
||||
moc.includePath = QFile::encodeName(parser.value(pathPrefixOption));
|
||||
}
|
||||
foreach (const QString &path, parser.values(includePathOption))
|
||||
const auto includePaths = parser.values(includePathOption);
|
||||
for (const QString &path : includePaths)
|
||||
pp.includes += Preprocessor::IncludePath(QFile::encodeName(path));
|
||||
foreach (const QString &path, parser.values(macFrameworkOption)) {
|
||||
const auto macFrameworks = parser.values(macFrameworkOption);
|
||||
for (const QString &path : macFrameworks) {
|
||||
// minimalistic framework support for the mac
|
||||
Preprocessor::IncludePath p(QFile::encodeName(path));
|
||||
p.isFrameworkPath = true;
|
||||
pp.includes += p;
|
||||
}
|
||||
foreach (const QString &arg, parser.values(defineOption)) {
|
||||
const auto defines = parser.values(defineOption);
|
||||
for (const QString &arg : defines) {
|
||||
QByteArray name = arg.toLocal8Bit();
|
||||
QByteArray value("1");
|
||||
int eq = name.indexOf('=');
|
||||
|
|
@ -334,7 +339,8 @@ int runMoc(int argc, char **argv)
|
|||
macro.symbols.removeLast(); // remove the EOF symbol
|
||||
pp.macros.insert(name, macro);
|
||||
}
|
||||
foreach (const QString &arg, parser.values(undefineOption)) {
|
||||
const auto undefines = parser.values(undefineOption);
|
||||
for (const QString &arg : undefines) {
|
||||
QByteArray macro = arg.toLocal8Bit();
|
||||
if (macro.isEmpty()) {
|
||||
error("Missing macro name");
|
||||
|
|
@ -379,7 +385,8 @@ int runMoc(int argc, char **argv)
|
|||
moc.filename = filename.toLocal8Bit();
|
||||
}
|
||||
|
||||
foreach (const QString &md, parser.values(metadataOption)) {
|
||||
const auto metadata = parser.values(metadataOption);
|
||||
for (const QString &md : metadata) {
|
||||
int split = md.indexOf(QLatin1Char('='));
|
||||
QString key = md.left(split);
|
||||
QString value = md.mid(split + 1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue