From da34a05d99e324ffc3ca802ca9d65db2a4e7eac9 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 9 Apr 2017 16:55:17 +1000 Subject: Further use of range-for. --- src/CaseConvert.cxx | 6 +++--- src/Catalogue.cxx | 14 ++++++-------- src/Document.cxx | 48 ++++++++++++++++++++++++------------------------ src/EditView.cxx | 10 +++++----- src/Editor.cxx | 5 ++--- src/PerLine.cxx | 6 +++--- src/PositionCache.cxx | 20 ++++++++++---------- src/Selection.cxx | 32 ++++++++++++++++---------------- src/XPM.cxx | 12 ++++++------ 9 files changed, 75 insertions(+), 78 deletions(-) (limited to 'src') diff --git a/src/CaseConvert.cxx b/src/CaseConvert.cxx index 4d0e5e271..24205dd81 100644 --- a/src/CaseConvert.cxx +++ b/src/CaseConvert.cxx @@ -653,9 +653,9 @@ public: std::sort(characterToConversion.begin(), characterToConversion.end()); characters.reserve(characterToConversion.size()); conversions.reserve(characterToConversion.size()); - for (CharacterToConversion::iterator it = characterToConversion.begin(); it != characterToConversion.end(); ++it) { - characters.push_back(it->character); - conversions.push_back(it->conversion); + for (const CharacterConversion &chConv : characterToConversion) { + characters.push_back(chConv.character); + conversions.push_back(chConv.conversion); } // Empty the original calculated data completely CharacterToConversion().swap(characterToConversion); diff --git a/src/Catalogue.cxx b/src/Catalogue.cxx index 8dbe1dde0..c4f7a7eda 100644 --- a/src/Catalogue.cxx +++ b/src/Catalogue.cxx @@ -28,10 +28,9 @@ static int nextLanguage = SCLEX_AUTOMATIC+1; const LexerModule *Catalogue::Find(int language) { Scintilla_LinkLexers(); - for (std::vector::iterator it=lexerCatalogue.begin(); - it != lexerCatalogue.end(); ++it) { - if ((*it)->GetLanguage() == language) { - return *it; + for (const LexerModule *lm : lexerCatalogue) { + if (lm->GetLanguage() == language) { + return lm; } } return 0; @@ -40,10 +39,9 @@ const LexerModule *Catalogue::Find(int language) { const LexerModule *Catalogue::Find(const char *languageName) { Scintilla_LinkLexers(); if (languageName) { - for (std::vector::iterator it=lexerCatalogue.begin(); - it != lexerCatalogue.end(); ++it) { - if ((*it)->languageName && (0 == strcmp((*it)->languageName, languageName))) { - return *it; + for (const LexerModule *lm : lexerCatalogue) { + if (lm->languageName && (0 == strcmp(lm->languageName, languageName))) { + return lm; } } } diff --git a/src/Document.cxx b/src/Document.cxx index d8fdc1153..d7e3bf62b 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -134,12 +134,12 @@ Document::Document() { } Document::~Document() { - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifyDeleted(this, it->userData); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifyDeleted(this, watcher.userData); } - for (int j=0; jInit(); + for (PerLine *pl : perLineData) { + if (pl) + pl->Init(); } } @@ -190,16 +190,16 @@ bool Document::SetLineEndTypesAllowed(int lineEndBitSet_) { } void Document::InsertLine(Sci::Line line) { - for (int j=0; jInsertLine(line); + for (PerLine *pl : perLineData) { + if (pl) + pl->InsertLine(line); } } void Document::RemoveLine(Sci::Line line) { - for (int j=0; jRemoveLine(line); + for (PerLine *pl : perLineData) { + if (pl) + pl->RemoveLine(line); } } @@ -383,8 +383,8 @@ Sci_Position SCI_METHOD Document::LineEnd(Sci_Position line) const { void SCI_METHOD Document::SetErrorStatus(int status) { // Tell the watchers an error has occurred. - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifyErrorOccurred(this, it->userData, status); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifyErrorOccurred(this, watcher.userData, status); } } @@ -2119,8 +2119,8 @@ void Document::StyleToAdjustingLineDuration(Sci::Position pos) { void Document::LexerChanged() { // Tell the watchers the lexer has changed. - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifyLexerChanged(this, it->userData); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifyLexerChanged(this, watcher.userData); } } @@ -2254,14 +2254,14 @@ bool Document::RemoveWatcher(DocWatcher *watcher, void *userData) { } void Document::NotifyModifyAttempt() { - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifyModifyAttempt(this, it->userData); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifyModifyAttempt(this, watcher.userData); } } void Document::NotifySavePoint(bool atSavePoint) { - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifySavePoint(this, it->userData, atSavePoint); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifySavePoint(this, watcher.userData, atSavePoint); } } @@ -2271,8 +2271,8 @@ void Document::NotifyModified(DocModification mh) { } else if (mh.modificationType & SC_MOD_DELETETEXT) { decorations.DeleteRange(mh.position, mh.length); } - for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { - it->watcher->NotifyModified(this, mh, it->userData); + for (const WatcherWithUserData &watcher : watchers) { + watcher.watcher->NotifyModified(this, mh, watcher.userData); } } diff --git a/src/EditView.cxx b/src/EditView.cxx index d3ebeeda5..d40ac51d8 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -2036,7 +2036,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan } else { phases.push_back(drawAll); } - for (std::vector::iterator it = phases.begin(); it != phases.end(); ++it) { + for (const DrawPhase &phase : phases) { int ypos = 0; if (!bufferedDraw) ypos += screenLinePaintFirst * vsDraw.lineHeight; @@ -2075,7 +2075,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan ll->SetBracesHighlight(rangeLine, model.braces, static_cast(model.bracesMatchStyle), static_cast(model.highlightGuideColumn * vsDraw.spaceWidth), bracesIgnoreStyle); - if (leftTextOverlap && (bufferedDraw || ((phasesDraw < phasesMultiple) && (*it & drawBack)))) { + if (leftTextOverlap && (bufferedDraw || ((phasesDraw < phasesMultiple) && (phase & drawBack)))) { // Clear the left margin PRectangle rcSpacer = rcLine; rcSpacer.right = rcSpacer.left; @@ -2083,17 +2083,17 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan surface->FillRectangle(rcSpacer, vsDraw.styles[STYLE_DEFAULT].back); } - DrawLine(surface, model, vsDraw, ll, lineDoc, visibleLine, xStart, rcLine, subLine, *it); + DrawLine(surface, model, vsDraw, ll, lineDoc, visibleLine, xStart, rcLine, subLine, phase); //durPaint += et.Duration(true); // Restore the previous styles for the brace highlights in case layout is in cache. ll->RestoreBracesHighlight(rangeLine, model.braces, bracesIgnoreStyle); - if (*it & drawFoldLines) { + if (phase & drawFoldLines) { DrawFoldLines(surface, model, vsDraw, lineDoc, rcLine); } - if (*it & drawCarets) { + if (phase & drawCarets) { DrawCarets(surface, model, vsDraw, ll, lineDoc, xStart, rcLine, subLine); } diff --git a/src/Editor.cxx b/src/Editor.cxx index 78b1845db..2c7c2e5a2 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -4147,9 +4147,8 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { std::vector rangesInOrder = sel.RangesCopy(); if (sel.selType == Selection::selRectangle) std::sort(rangesInOrder.begin(), rangesInOrder.end()); - for (size_t r=0; reolMode != SC_EOL_LF) text.push_back('\r'); diff --git a/src/PerLine.cxx b/src/PerLine.cxx index abe2230e6..f26b48b77 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -548,9 +548,9 @@ int LineTabstops::GetNextTabstop(Sci::Line line, int x) const { if (line < tabstops.Length()) { TabstopList *tl = tabstops[line]; if (tl) { - for (size_t i = 0; i < tl->size(); i++) { - if ((*tl)[i] > x) { - return (*tl)[i]; + for (const int i : *tl) { + if (i > x) { + return i; } } } diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 1b69fccdb..6df915b8b 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -293,16 +293,16 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI void LineLayoutCache::Deallocate() { PLATFORM_ASSERT(useCount == 0); - for (size_t i = 0; i < cache.size(); i++) - delete cache[i]; + for (LineLayout *ll : cache) + delete ll; cache.clear(); } void LineLayoutCache::Invalidate(LineLayout::validLevel validity_) { if (!cache.empty() && !allInvalidated) { - for (size_t i = 0; i < cache.size(); i++) { - if (cache[i]) { - cache[i]->Invalidate(validity_); + for (LineLayout *ll : cache) { + if (ll) { + ll->Invalidate(validity_); } } if (validity_ == LineLayout::llInvalid) { @@ -482,7 +482,7 @@ BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lin } } } - if (pvsDraw && pvsDraw->indicatorsSetFore > 0) { + if (pvsDraw && pvsDraw->indicatorsSetFore) { for (Decoration *deco = pdoc->decorations.Root(); deco; deco = deco->Next()) { if (pvsDraw->indicators[deco->Indicator()].OverridesTextFore()) { Sci::Position startPos = deco->rs.EndRun(posLineStart); @@ -639,8 +639,8 @@ PositionCache::~PositionCache() { void PositionCache::Clear() { if (!allClear) { - for (size_t i=0; i 60000) { // Since there are only 16 bits for the clock, wrap it round and // reset all cache entries so none get stuck with a high clock. - for (size_t i=0; isecond->GetHeight()) { - height = it->second->GetHeight(); + for (const std::pair &image : images) { + if (height < image.second->GetHeight()) { + height = image.second->GetHeight(); } } } @@ -294,9 +294,9 @@ int RGBAImageSet::GetHeight() const { /// Give the largest width of the set. int RGBAImageSet::GetWidth() const { if (width < 0) { - for (ImageMap::const_iterator it=images.begin(); it != images.end(); ++it) { - if (width < it->second->GetWidth()) { - width = it->second->GetWidth(); + for (const std::pair &image : images) { + if (width < image.second->GetWidth()) { + width = image.second->GetWidth(); } } } -- cgit v1.2.3