Moc: use const (and const APIs) more
For CoW types, prefer const methods to avoid needless detach()ing. Change-Id: Iefc33552d826aa30320e52acd2d421c9bdae127e Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
5361a8dec5
commit
777d46b403
@ -79,7 +79,7 @@ Generator::Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes, con
|
||||
, knownGadgets(knownGadgets)
|
||||
{
|
||||
if (cdef->superclassList.size())
|
||||
purestSuperClass = cdef->superclassList.first().first;
|
||||
purestSuperClass = cdef->superclassList.constFirst().first;
|
||||
}
|
||||
|
||||
static inline int lengthOfEscapeSequence(const QByteArray &s, int i)
|
||||
|
@ -360,7 +360,7 @@ int runMoc(int argc, char **argv)
|
||||
int spos = filename.lastIndexOf(QDir::separator());
|
||||
int ppos = filename.lastIndexOf(QLatin1Char('.'));
|
||||
// spos >= -1 && ppos > spos => ppos >= 0
|
||||
moc.noInclude = (ppos > spos && filename[ppos + 1].toLower() != QLatin1Char('h'));
|
||||
moc.noInclude = (ppos > spos && filename.at(ppos + 1).toLower() != QLatin1Char('h'));
|
||||
}
|
||||
if (defaultInclude) {
|
||||
if (moc.includePath.isEmpty()) {
|
||||
|
@ -136,7 +136,7 @@ bool Moc::parseClassHead(ClassDef *def)
|
||||
} while (test(COMMA));
|
||||
|
||||
if (!def->superclassList.isEmpty()
|
||||
&& knownGadgets.contains(def->superclassList.first().first)) {
|
||||
&& knownGadgets.contains(def->superclassList.constFirst().first)) {
|
||||
// Q_GADGET subclasses are treated as Q_GADGETs
|
||||
knownGadgets.insert(def->classname, def->qualified);
|
||||
knownGadgets.insert(def->qualified, def->qualified);
|
||||
@ -312,7 +312,7 @@ void Moc::parseFunctionArguments(FunctionDef *def)
|
||||
}
|
||||
|
||||
if (!def->arguments.isEmpty()
|
||||
&& def->arguments.last().normalizedType == "QPrivateSignal") {
|
||||
&& def->arguments.constLast().normalizedType == "QPrivateSignal") {
|
||||
def->arguments.removeLast();
|
||||
def->isPrivateSignal = true;
|
||||
}
|
||||
@ -730,7 +730,7 @@ void Moc::parse()
|
||||
if (funcDef.isConstructor) {
|
||||
if ((access == FunctionDef::Public) && funcDef.isInvokable) {
|
||||
def.constructorList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def.constructorList += funcDef;
|
||||
@ -743,7 +743,7 @@ void Moc::parse()
|
||||
def.publicList += funcDef;
|
||||
if (funcDef.isSlot) {
|
||||
def.slotList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def.slotList += funcDef;
|
||||
@ -752,7 +752,7 @@ void Moc::parse()
|
||||
++def.revisionedMethods;
|
||||
} else if (funcDef.isSignal) {
|
||||
def.signalList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def.signalList += funcDef;
|
||||
@ -761,7 +761,7 @@ void Moc::parse()
|
||||
++def.revisionedMethods;
|
||||
} else if (funcDef.isInvokable) {
|
||||
def.methodList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def.methodList += funcDef;
|
||||
@ -863,7 +863,7 @@ void Moc::generate(FILE *out)
|
||||
{
|
||||
QByteArray fn = filename;
|
||||
int i = filename.length()-1;
|
||||
while (i>0 && filename[i-1] != '/' && filename[i-1] != '\\')
|
||||
while (i > 0 && filename.at(i - 1) != '/' && filename.at(i - 1) != '\\')
|
||||
--i; // skip path
|
||||
if (i >= 0)
|
||||
fn = filename.mid(i);
|
||||
@ -879,7 +879,7 @@ void Moc::generate(FILE *out)
|
||||
includePath += '/';
|
||||
for (int i = 0; i < includeFiles.size(); ++i) {
|
||||
QByteArray inc = includeFiles.at(i);
|
||||
if (inc[0] != '<' && inc[0] != '"') {
|
||||
if (inc.at(0) != '<' && inc.at(0) != '"') {
|
||||
if (includePath.size() && includePath != "./")
|
||||
inc.prepend(includePath);
|
||||
inc = '\"' + inc + '\"';
|
||||
@ -887,7 +887,7 @@ void Moc::generate(FILE *out)
|
||||
fprintf(out, "#include %s\n", inc.constData());
|
||||
}
|
||||
}
|
||||
if (classList.size() && classList.first().classname == "Qt")
|
||||
if (classList.size() && classList.constFirst().classname == "Qt")
|
||||
fprintf(out, "#include <QtCore/qobject.h>\n");
|
||||
|
||||
fprintf(out, "#include <QtCore/qbytearray.h>\n"); // For QByteArrayData
|
||||
@ -965,7 +965,7 @@ void Moc::parseSlots(ClassDef *def, FunctionDef::Access access)
|
||||
++def->revisionedMethods;
|
||||
}
|
||||
def->slotList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def->slotList += funcDef;
|
||||
@ -1021,7 +1021,7 @@ void Moc::parseSignals(ClassDef *def)
|
||||
++def->revisionedMethods;
|
||||
}
|
||||
def->signalList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def->signalList += funcDef;
|
||||
@ -1059,7 +1059,7 @@ void Moc::createPropertyDef(PropertyDef &propDef)
|
||||
next();
|
||||
propDef.name = lexem();
|
||||
while (test(IDENTIFIER)) {
|
||||
QByteArray l = lexem();
|
||||
const QByteArray l = lexem();
|
||||
if (l[0] == 'C' && l == "CONSTANT") {
|
||||
propDef.constant = true;
|
||||
continue;
|
||||
@ -1395,7 +1395,7 @@ void Moc::parseSlotInPrivate(ClassDef *def, FunctionDef::Access access)
|
||||
funcDef.access = access;
|
||||
parseFunction(&funcDef, true);
|
||||
def->slotList += funcDef;
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
|
||||
while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) {
|
||||
funcDef.wasCloned = true;
|
||||
funcDef.arguments.removeLast();
|
||||
def->slotList += funcDef;
|
||||
@ -1539,7 +1539,7 @@ void Moc::checkSuperClasses(ClassDef *def)
|
||||
if (interface2IdMap.contains(superClass)) {
|
||||
bool registeredInterface = false;
|
||||
for (int i = 0; i < def->interfaceList.count(); ++i)
|
||||
if (def->interfaceList.at(i).first().className == superClass) {
|
||||
if (def->interfaceList.at(i).constFirst().className == superClass) {
|
||||
registeredInterface = true;
|
||||
break;
|
||||
}
|
||||
|
@ -205,13 +205,13 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
|
||||
// STRING_LITERAL handling in moc
|
||||
if (!Preprocessor::preprocessOnly
|
||||
&& !symbols.isEmpty()
|
||||
&& symbols.last().token == STRING_LITERAL) {
|
||||
&& symbols.constLast().token == STRING_LITERAL) {
|
||||
|
||||
QByteArray newString = symbols.last().unquotedLexem();
|
||||
QByteArray newString = symbols.constLast().unquotedLexem();
|
||||
newString += input.mid(lexem - begin + 1, data - lexem - 2);
|
||||
newString.prepend('\"');
|
||||
newString.append('\"');
|
||||
symbols.last() = Symbol(symbols.last().lineNum,
|
||||
symbols.last() = Symbol(symbols.constLast().lineNum,
|
||||
STRING_LITERAL,
|
||||
newString);
|
||||
continue;
|
||||
@ -679,7 +679,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
|
||||
if (s.token == WHITESPACE)
|
||||
continue;
|
||||
|
||||
while (expansion.size() && expansion.last().token == PP_WHITESPACE)
|
||||
while (expansion.size() && expansion.constLast().token == PP_WHITESPACE)
|
||||
expansion.pop_back();
|
||||
|
||||
Symbol next = s;
|
||||
@ -692,8 +692,8 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
|
||||
next = arg.at(0);
|
||||
}
|
||||
|
||||
if (!expansion.isEmpty() && expansion.last().token == s.token) {
|
||||
Symbol last = expansion.last();
|
||||
if (!expansion.isEmpty() && expansion.constLast().token == s.token) {
|
||||
Symbol last = expansion.constLast();
|
||||
expansion.pop_back();
|
||||
|
||||
if (last.token == STRING_LITERAL || s.token == STRING_LITERAL)
|
||||
@ -1127,12 +1127,12 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
|
||||
}
|
||||
// remove trailing whitespace
|
||||
while (!macro.symbols.isEmpty() &&
|
||||
(macro.symbols.last().token == PP_WHITESPACE || macro.symbols.last().token == WHITESPACE))
|
||||
(macro.symbols.constLast().token == PP_WHITESPACE || macro.symbols.constLast().token == WHITESPACE))
|
||||
macro.symbols.pop_back();
|
||||
|
||||
if (!macro.symbols.isEmpty()) {
|
||||
if (macro.symbols.first().token == PP_HASHHASH ||
|
||||
macro.symbols.last().token == PP_HASHHASH) {
|
||||
if (macro.symbols.constFirst().token == PP_HASHHASH ||
|
||||
macro.symbols.constLast().token == PP_HASHHASH) {
|
||||
error("'##' cannot appear at either end of a macro expansion");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user