Commit bdb51421 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: use argumentCount in loops in initializer.

argumentCount is a more expensive function, so try to call it only once,
esp. in loops.

Change-Id: I6f0d420352743ec444487ce3f506ef28e5282d1e
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent fb28c145
......@@ -235,11 +235,12 @@ bool Function::isEqualTo(const Type *other) const
const Name *l = unqualifiedName();
const Name *r = o->unqualifiedName();
if (l == r || (l && l->isEqualTo(r))) {
if (argumentCount() != o->argumentCount())
const unsigned argc = argumentCount();
if (argc != o->argumentCount())
return false;
else if (! _returnType.isEqualTo(o->_returnType))
return false;
for (unsigned i = 0; i < argumentCount(); ++i) {
for (unsigned i = 0; i < argc; ++i) {
Symbol *l = argumentAt(i);
Symbol *r = o->argumentAt(i);
if (! l->type().isEqualTo(r->type()))
......@@ -297,15 +298,15 @@ Symbol *Function::argumentAt(unsigned index) const
bool Function::hasArguments() const
{
return ! (argumentCount() == 0 ||
(argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
unsigned argc = argumentCount();
return ! (argc == 0 || (argc == 1 && argumentAt(0)->type()->isVoidType()));
}
unsigned Function::minimumArgumentCount() const
{
unsigned index = 0;
for (; index < argumentCount(); ++index) {
for (unsigned ei = argumentCount(); index < ei; ++index) {
if (Argument *arg = argumentAt(index)->asArgument()) {
if (arg->hasInitializer())
break;
......@@ -374,10 +375,11 @@ void Function::visitSymbol0(SymbolVisitor *visitor)
bool Function::maybeValidPrototype(unsigned actualArgumentCount) const
{
const unsigned argc = argumentCount();
unsigned minNumberArguments = 0;
for (; minNumberArguments < this->argumentCount(); ++minNumberArguments) {
Argument *arg = this->argumentAt(minNumberArguments)->asArgument();
for (; minNumberArguments < argc; ++minNumberArguments) {
Argument *arg = argumentAt(minNumberArguments)->asArgument();
if (! arg) // TODO: Fix me properly - QTCREATORBUG-8316
return false;
......@@ -390,7 +392,7 @@ bool Function::maybeValidPrototype(unsigned actualArgumentCount) const
// not enough arguments.
return false;
} else if (! this->isVariadic() && actualArgumentCount > this->argumentCount()) {
} else if (!isVariadic() && actualArgumentCount > argc) {
// too many arguments.
return false;
}
......
......@@ -145,7 +145,7 @@ public:
funTy->setReturnType(rewrite->rewriteType(type->returnType()));
for (unsigned i = 0; i < type->argumentCount(); ++i) {
for (unsigned i = 0, argc = type->argumentCount(); i < argc; ++i) {
Symbol *arg = type->argumentAt(i);
Argument *newArg = control()->newArgument(0, 0);
......
......@@ -140,7 +140,7 @@ private:
fun->setReturnType(q->apply(funTy->returnType()));
for (unsigned i = 0; i < funTy->argumentCount(); ++i) {
for (unsigned i = 0, argc = funTy->argumentCount(); i < argc; ++i) {
Argument *originalArgument = funTy->argumentAt(i)->asArgument();
Argument *arg = control()->newArgument(/*sourceLocation*/ 0,
originalArgument->name());
......
......@@ -638,7 +638,7 @@ bool ResolveExpression::visit(CallAST *ast)
int score = 0;
for (unsigned i = 0; i < funTy->argumentCount(); ++i) {
for (unsigned i = 0, argc = funTy->argumentCount(); i < argc; ++i) {
const FullySpecifiedType formalTy = funTy->argumentAt(i)->type();
FullySpecifiedType actualTy;
......
......@@ -409,7 +409,7 @@ void TypePrettyPrinter::visit(Function *type)
_text += QLatin1Char('(');
for (unsigned index = 0; index < type->argumentCount(); ++index) {
for (unsigned index = 0, argc = type->argumentCount(); index < argc; ++index) {
if (index != 0)
_text += QLatin1String(", ");
......
......@@ -381,10 +381,10 @@ void FunctionDeclDefLink::showMarker(CPPEditorWidget *editor)
// does consider foo(void) to have one argument
static int declaredParameterCount(Function *function)
{
int c = function->argumentCount();
if (c == 0 && function->memberCount() > 0 && function->memberAt(0)->type().type()->isVoidType())
int argc = function->argumentCount();
if (argc == 0 && function->memberCount() > 0 && function->memberAt(0)->type().type()->isVoidType())
return 1;
return c;
return argc;
}
Q_GLOBAL_STATIC(QRegExp, commentArgNameRegexp)
......
......@@ -1364,7 +1364,7 @@ void CppCompletionAssistProcessor::globalCompletion(CPlusPlus::Scope *currentSco
}
} else if (scope->isFunction()) {
Function *fun = scope->asFunction();
for (unsigned i = 0; i < fun->argumentCount(); ++i) {
for (unsigned i = 0, argc = fun->argumentCount(); i < argc; ++i) {
addCompletionItem(fun->argumentAt(i), FunctionArgumentsOrder);
}
break;
......
......@@ -185,15 +185,16 @@ Symbol *SymbolFinder::findMatchingDefinition(Symbol *declaration,
if (! strict && ! best)
best = fun;
unsigned argc = 0;
for (; argc < declarationTy->argumentCount(); ++argc) {
Symbol *arg = fun->argumentAt(argc);
Symbol *otherArg = declarationTy->argumentAt(argc);
const unsigned argc = declarationTy->argumentCount();
unsigned argIt = 0;
for (; argIt < argc; ++argIt) {
Symbol *arg = fun->argumentAt(argIt);
Symbol *otherArg = declarationTy->argumentAt(argIt);
if (! arg->type().isEqualTo(otherArg->type()))
break;
}
if (argc == declarationTy->argumentCount())
if (argIt == argc)
best = fun;
}
}
......
......@@ -569,7 +569,7 @@ static LanguageUtils::FakeMetaObject::Ptr buildFakeMetaObject(
method.setMethodType(FakeMetaMethod::Signal);
else
method.setMethodType(FakeMetaMethod::Slot);
for (unsigned a = 0; a < func->argumentCount(); ++a) {
for (unsigned a = 0, argc = func->argumentCount(); a < argc; ++a) {
Symbol *arg = func->argumentAt(a);
QString name;
if (arg->name())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment