Skip to content

[NFC] Pre- increment and decrement where possible #32118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Remote/Failure.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Failure {
result.append(text, next - text);

// Skip the '%'.
next++;
++next;

// Do something based on the character after '%'.
char c = *next++;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Runtime/Concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ template <class ElemTy> struct ConcurrentReadableArray {
}

void deallocate() {
for (size_t i = 0; i < Count; i++) {
for (size_t i = 0; i < Count; ++i) {
data()[i].~ElemTy();
}
free(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
LOAD(dumpInfoForTypeRef);

Library->IsLegacy = IsLegacy;
Context->LibraryCount++;
++Context->LibraryCount;

return 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3846,7 +3846,7 @@ void SubstitutionMap::Storage::Profile(
id.AddPointer(replacementTypes[i].getPointer());
else
id.AddPointer(nullptr);
i++;
++i;
});

// Conformances.
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
auto *aliasDecl = cast<TypeAliasDecl>(decl);

auto genericSig = aliasDecl->getGenericSignature();
for (unsigned i = 0, e = args.size(); i < e; i++) {
for (unsigned i = 0, e = args.size(); i < e; ++i) {
auto origTy = genericSig->getInnermostGenericParams()[i];
auto substTy = args[i];

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ void PrintAST::printGenericSignature(
// Move index to genericParams.
unsigned lastParamIdx = paramIdx;
do {
lastParamIdx++;
++lastParamIdx;
} while (lastParamIdx < numParam &&
genericParams[lastParamIdx]->getDepth() == depth);

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ class Verifier : public ASTWalker {
// Look through optional evaluations.
if (auto *optionalEval = dyn_cast<OptionalEvaluationExpr>(subExpr)) {
subExpr = optionalEval->getSubExpr();
optionalDepth++;
++optionalDepth;
continue;
}

Expand Down Expand Up @@ -3165,7 +3165,7 @@ class Verifier : public ASTWalker {
unsigned NumDestructors = 0;
for (auto Member : CD->getMembers()) {
if (isa<DestructorDecl>(Member)) {
NumDestructors++;
++NumDestructors;
}
}
if (NumDestructors > 1) {
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ getBuiltinGenericFunction(Identifier Id,
DeclContext *DC = &M->getMainFile(FileUnitKind::Builtin);

SmallVector<ParamDecl*, 4> params;
for (unsigned i = 0, e = ArgParamTypes.size(); i < e; i++) {
for (unsigned i = 0, e = ArgParamTypes.size(); i < e; ++i) {
auto paramIfaceType = ArgParamTypes[i].getPlainType();
auto specifier =
ParamDecl::getParameterSpecifierForValueOwnership(
Expand Down Expand Up @@ -2004,11 +2004,11 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {

// Accept weak, volatile, and singlethread if present.
if (NextPart != Parts.end() && *NextPart == "weak")
NextPart++;
++NextPart;
if (NextPart != Parts.end() && *NextPart == "volatile")
NextPart++;
++NextPart;
if (NextPart != Parts.end() && *NextPart == "singlethread")
NextPart++;
++NextPart;
// Nothing else is allowed in the name.
if (NextPart != Parts.end())
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ClangTypeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ clang::QualType ClangTypeConverter::visitTupleType(TupleType *type) {
return ClangASTContext.VoidTy;

Type eltTy = type->getElementType(0);
for (unsigned i = 1; i < tupleNumElements; i++) {
for (unsigned i = 1; i < tupleNumElements; ++i) {
if (!eltTy->isEqual(type->getElementType(i)))
// Only tuples where all element types are equal map to fixed-size
// arrays.
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5035,7 +5035,7 @@ ProtocolDecl::setLazyRequirementSignature(LazyMemberLoader *lazyLoader,
++NumLazyRequirementSignatures;
// FIXME: (transitional) increment the redundant "always-on" counter.
if (auto *Stats = getASTContext().Stats)
Stats->getFrontendCounters().NumLazyRequirementSignatures++;
++Stats->getFrontendCounters().NumLazyRequirementSignatures;
}

ArrayRef<Requirement> ProtocolDecl::getCachedRequirementSignature() const {
Expand Down Expand Up @@ -5195,7 +5195,7 @@ AbstractStorageDecl::AccessorRecord::create(ASTContext &ctx,
case AccessorKind::ID: \
if (!has##ID) { \
has##ID = true; \
numMissingOpaque--; \
--numMissingOpaque; \
} \
continue;
#include "swift/AST/AccessorKinds.def"
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ void IterableDeclContext::loadAllMembers() const {
--NumUnloadedLazyIterableDeclContexts;
// FIXME: (transitional) decrement the redundant "always-on" counter.
if (auto s = ctx.Stats)
s->getFrontendCounters().NumUnloadedLazyIterableDeclContexts--;
--s->getFrontendCounters().NumUnloadedLazyIterableDeclContexts;
}

bool IterableDeclContext::wasDeserialized() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
SmallString<128> notePath(getDiagnosticDocumentationPath());
llvm::sys::path::append(notePath, *associatedNotes);
educationalNotePaths.push_back(notePath.str().str());
associatedNotes++;
++associatedNotes;
}
info->EducationalNotePaths = educationalNotePaths;

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GenericSignatureImpl::GenericSignatureImpl(
count = 0;
}
assert(param->getIndex() == count && "Generic parameter index mismatch");
count++;
++count;
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3431,7 +3431,7 @@ EquivalenceClass::EquivalenceClass(PotentialArchetype *representative)
}

void EquivalenceClass::modified(GenericSignatureBuilder &builder) {
builder.Impl->Generation++;
++builder.Impl->Generation;

// Transfer any delayed requirements to the primary queue, because they
// might be resolvable now.
Expand All @@ -3444,7 +3444,7 @@ GenericSignatureBuilder::GenericSignatureBuilder(
ASTContext &ctx)
: Context(ctx), Diags(Context.Diags), Impl(new Implementation) {
if (auto *Stats = Context.Stats)
Stats->getFrontendCounters().NumGenericSignatureBuilders++;
++Stats->getFrontendCounters().NumGenericSignatureBuilders;
}

GenericSignatureBuilder::GenericSignatureBuilder(
Expand Down Expand Up @@ -3822,7 +3822,7 @@ static ConstraintResult visitInherited(
unsigned index = 0;
for (auto memberType : compositionType->getMembers()) {
visitInherited(memberType, composition->getTypes()[index]);
index++;
++index;
}

return;
Expand Down
16 changes: 8 additions & 8 deletions lib/AST/ImportCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ ImportCache::getImportSet(ASTContext &ctx,

if (ImportSet *result = ImportSets.FindNodeOrInsertPos(ID, InsertPos)) {
if (ctx.Stats)
ctx.Stats->getFrontendCounters().ImportSetFoldHit++;
++ctx.Stats->getFrontendCounters().ImportSetFoldHit;
return *result;
}

if (ctx.Stats)
ctx.Stats->getFrontendCounters().ImportSetFoldMiss++;
++ctx.Stats->getFrontendCounters().ImportSetFoldMiss;

SmallVector<ModuleDecl::ImportedModule, 4> stack;
for (auto next : topLevelImports) {
Expand Down Expand Up @@ -166,12 +166,12 @@ ImportSet &ImportCache::getImportSet(const DeclContext *dc) {
auto found = ImportSetForDC.find(dc);
if (found != ImportSetForDC.end()) {
if (ctx.Stats)
ctx.Stats->getFrontendCounters().ImportSetCacheHit++;
++ctx.Stats->getFrontendCounters().ImportSetCacheHit;
return *found->second;
}

if (ctx.Stats)
ctx.Stats->getFrontendCounters().ImportSetCacheMiss++;
++ctx.Stats->getFrontendCounters().ImportSetCacheMiss;

SmallVector<ModuleDecl::ImportedModule, 4> imports;

Expand Down Expand Up @@ -213,12 +213,12 @@ ImportCache::getAllVisibleAccessPaths(const ModuleDecl *mod,
auto found = VisibilityCache.find(key);
if (found != VisibilityCache.end()) {
if (ctx.Stats)
ctx.Stats->getFrontendCounters().ModuleVisibilityCacheHit++;
++ctx.Stats->getFrontendCounters().ModuleVisibilityCacheHit;
return found->second;
}

if (ctx.Stats)
ctx.Stats->getFrontendCounters().ModuleVisibilityCacheMiss++;
++ctx.Stats->getFrontendCounters().ModuleVisibilityCacheMiss;

SmallVector<ModuleDecl::AccessPathTy, 1> accessPaths;
for (auto next : getImportSet(dc).getAllImports()) {
Expand Down Expand Up @@ -251,12 +251,12 @@ ImportCache::getAllAccessPathsNotShadowedBy(const ModuleDecl *mod,
auto found = ShadowCache.find(key);
if (found != ShadowCache.end()) {
if (ctx.Stats)
ctx.Stats->getFrontendCounters().ModuleShadowCacheHit++;
++ctx.Stats->getFrontendCounters().ModuleShadowCacheHit;
return found->second;
}

if (ctx.Stats)
ctx.Stats->getFrontendCounters().ModuleShadowCacheMiss++;
++ctx.Stats->getFrontendCounters().ModuleShadowCacheMiss;

SmallVector<ModuleDecl::ImportedModule, 4> stack;
llvm::SmallDenseSet<ModuleDecl::ImportedModule, 32> visited;
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void ModuleDecl::lookupValue(DeclName Name, NLKind LookupKind,
SmallVectorImpl<ValueDecl*> &Result) const {
auto *stats = getASTContext().Stats;
if (stats)
stats->getFrontendCounters().NumModuleLookupValue++;
++stats->getFrontendCounters().NumModuleLookupValue;

if (isParsedModule(this)) {
getSourceLookupCache().lookupValue(Name, LookupKind, Result);
Expand Down Expand Up @@ -709,7 +709,7 @@ void ModuleDecl::lookupClassMember(AccessPathTy accessPath,
SmallVectorImpl<ValueDecl*> &results) const {
auto *stats = getASTContext().Stats;
if (stats)
stats->getFrontendCounters().NumModuleLookupClassMember++;
++stats->getFrontendCounters().NumModuleLookupClassMember;

if (isParsedModule(this)) {
FrontendStatsTracer tracer(getASTContext().Stats,
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ void LookupResult::filter(
Results.erase(std::remove_if(Results.begin(), Results.end(),
[&](LookupResultEntry result) -> bool {
auto isInner = index < originalFirstOuter;
index++;
++index;
if (pred(result, !isInner))
return false;

// Need to remove this, which means, if it is
// an inner result, the outer results need to
// shift down.
if (isInner)
IndexOfFirstOuterResult--;
--IndexOfFirstOuterResult;
return true;
}),
Results.end());
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/RequirementEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RequirementEnvironment::RequirementEnvironment(
// appear in the synthetic signature.
unsigned depth = 0;
if (covariantSelf) {
depth++;
++depth;
}
if (conformanceSig) {
depth += conformanceSig->getGenericParams().back()->getDepth() + 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
reqt.getSecondType()->isEqual(proto->getDeclaredType()))
return getConformances()[index];

index++;
++index;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,7 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
// Continue looking into the parent.
if (auto protocolTy = baseTy->getAs<ProtocolType>()) {
baseTy = protocolTy->getParent();
n--;
--n;
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Basic/Mangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static llvm::StringMap<OpStatEntry> OpStats;
void Mangler::recordOpStatImpl(StringRef op, size_t OldPos) {
if (PrintSwiftManglingStats) {
OpStatEntry &E = OpStats[op];
E.num++;
++E.num;
E.size += Storage.size() - OldPos;
}
}
Expand Down Expand Up @@ -218,15 +218,15 @@ bool Mangler::tryMangleSubstitution(const void *ptr) {
void Mangler::mangleSubstitution(unsigned Idx) {
if (Idx >= 26) {
#ifndef NDEBUG
numLargeSubsts++;
++numLargeSubsts;
#endif
return appendOperator("A", Index(Idx - 26));
}

char Subst = Idx + 'A';
if (SubstMerging.tryMergeSubst(*this, Subst, /*isStandardSubst*/ false)) {
#ifndef NDEBUG
mergedSubsts++;
++mergedSubsts;
#endif
} else {
appendOperator("A", StringRef(&Subst, 1));
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/PrimitiveParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ unsigned swift::measureNewline(const char *BufferPtr, const char *BufferEnd) {
assert(*BufferPtr == '\r');
unsigned Bytes = 1;
if (BufferPtr != BufferEnd && *BufferPtr == '\n')
Bytes++;
++Bytes;
return Bytes;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Basic/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ class UnifiedStatsReporter::RecursionSafeTimers {
if (T.RecursionDepth == 0) {
T.Timer.emplace(Name);
}
T.RecursionDepth++;
++T.RecursionDepth;
}

void endTimer(StringRef Name) {
auto I = Timers.find(Name);
assert(I != Timers.end());
RecursionSafeTimer &T = I->getValue();
assert(T.RecursionDepth != 0);
T.RecursionDepth--;
--T.RecursionDepth;
if (T.RecursionDepth == 0) {
T.Timer.reset();
}
Expand Down Expand Up @@ -651,10 +651,10 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
if (currentProcessExitStatus != EXIT_SUCCESS) {
if (FrontendCounters) {
auto &C = getFrontendCounters();
C.NumProcessFailures++;
++C.NumProcessFailures;
} else {
auto &C = getDriverCounters();
C.NumProcessFailures++;
++C.NumProcessFailures;
}
}

Expand Down
Loading