From 1a35c89b60c7e487d005c632b1e8f7e00eb961ab Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 3 May 2018 07:48:10 +1000 Subject: Use Range and Position in more cases to avoid casts. --- src/PositionCache.cxx | 33 ++++++++++++++++++--------------- src/PositionCache.h | 4 ++-- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 88415abfe..8ed0580bb 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -177,9 +177,11 @@ void LineLayout::RestoreBracesHighlight(Range rangeLine, const Sci::Position bra xHighlightGuide = 0; } -int LineLayout::FindBefore(XYPOSITION x, int lower, int upper) const { +int LineLayout::FindBefore(XYPOSITION x, Range range) const { + Sci::Position lower = range.start; + Sci::Position upper = range.end; do { - const int middle = (upper + lower + 1) / 2; // Round high + const Sci::Position middle = (upper + lower + 1) / 2; // Round high const XYPOSITION posMiddle = positions[middle]; if (x < posMiddle) { upper = middle - 1; @@ -187,12 +189,12 @@ int LineLayout::FindBefore(XYPOSITION x, int lower, int upper) const { lower = middle; } } while (lower < upper); - return lower; + return static_cast(lower); } int LineLayout::FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const { - int pos = FindBefore(x, static_cast(range.start), static_cast(range.end)); + int pos = FindBefore(x, range); while (pos < range.end) { if (charPosition) { if (x < (positions[pos + 1])) { @@ -429,13 +431,14 @@ void SpecialRepresentations::Clear() { std::fill(startByteHasReprs, std::end(startByteHasReprs), none); } -void BreakFinder::Insert(int val) { - if (val > nextBreak) { - const std::vector::iterator it = std::lower_bound(selAndEdge.begin(), selAndEdge.end(), val); +void BreakFinder::Insert(Sci::Position val) { + int posInLine = static_cast(val); + if (posInLine > nextBreak) { + const std::vector::iterator it = std::lower_bound(selAndEdge.begin(), selAndEdge.end(), posInLine); if (it == selAndEdge.end()) { - selAndEdge.push_back(val); - } else if (*it != val) { - selAndEdge.insert(it, 1, val); + selAndEdge.push_back(posInLine); + } else if (*it != posInLine) { + selAndEdge.insert(it, 1, posInLine); } } } @@ -456,7 +459,7 @@ BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lin // Search for first visible break // First find the first visible character if (xStart > 0.0f) - nextBreak = ll->FindBefore(static_cast(xStart), static_cast(lineRange.start), static_cast(lineRange.end)); + nextBreak = ll->FindBefore(static_cast(xStart), lineRange); // Now back to a style break while ((nextBreak > lineRange.start) && (ll->styles[nextBreak] == ll->styles[nextBreak - 1])) { nextBreak--; @@ -470,9 +473,9 @@ BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lin const SelectionSegment portion = psel->Range(r).Intersect(segmentLine); if (!(portion.start == portion.end)) { if (portion.start.IsValid()) - Insert(static_cast(portion.start.Position() - posLineStart)); + Insert(portion.start.Position() - posLineStart); if (portion.end.IsValid()) - Insert(static_cast(portion.end.Position() - posLineStart)); + Insert(portion.end.Position() - posLineStart); } } } @@ -481,14 +484,14 @@ BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lin if (pvsDraw->indicators[deco->Indicator()].OverridesTextFore()) { Sci::Position startPos = deco->EndRun(posLineStart); while (startPos < (posLineStart + lineRange.end)) { - Insert(static_cast(startPos - posLineStart)); + Insert(startPos - posLineStart); startPos = deco->EndRun(startPos); } } } } Insert(ll->edgeColumn); - Insert(static_cast(lineRange.end)); + Insert(lineRange.end); saeNext = (!selAndEdge.empty()) ? selAndEdge[0] : -1; } diff --git a/src/PositionCache.h b/src/PositionCache.h index c1ecd2c0f..2b3ea1485 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -92,7 +92,7 @@ public: void SetBracesHighlight(Range rangeLine, const Sci::Position braces[], char bracesMatchStyle, int xHighlight, bool ignoreStyle); void RestoreBracesHighlight(Range rangeLine, const Sci::Position braces[], bool ignoreStyle); - int FindBefore(XYPOSITION x, int lower, int upper) const; + int FindBefore(XYPOSITION x, Range range) const; int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const; Point PointFromPosition(int posInLine, int lineHeight, PointEnd pe) const; int EndLineStyle() const; @@ -199,7 +199,7 @@ class BreakFinder { const Document *pdoc; EncodingFamily encodingFamily; const SpecialRepresentations *preprs; - void Insert(int val); + void Insert(Sci::Position val); public: // If a whole run is longer than lengthStartSubdivision then subdivide // into smaller runs at spaces or punctuation. -- cgit v1.2.3