From 2d24504cd1fdd777bc8b7b6eff9c97101beff0cd Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 29 Jan 2025 11:15:49 +0100 Subject: [PATCH] Change the return type of RangedValues::getIntersectionsWith This is to avoid converting the returned value to RangedValues at the call site. --- modules/juce_graphics/detail/juce_Ranges.cpp | 8 ++++---- modules/juce_graphics/detail/juce_Ranges.h | 7 +++---- modules/juce_graphics/detail/juce_SimpleShapedText.cpp | 2 +- modules/juce_graphics/fonts/juce_TextLayout.cpp | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/juce_graphics/detail/juce_Ranges.cpp b/modules/juce_graphics/detail/juce_Ranges.cpp index ea05cd2f17..fda3bcb405 100644 --- a/modules/juce_graphics/detail/juce_Ranges.cpp +++ b/modules/juce_graphics/detail/juce_Ranges.cpp @@ -557,15 +557,15 @@ public: { const auto intersections = rangedValues.getIntersectionsWith ({ 5, 43 }); - expectRangedValuesItem (intersections[0], { 5, 10 }, 'a'); - expectRangedValuesItem (intersections[1], { 11, 20 }, 'b'); - expectRangedValuesItem (intersections[2], { 23, 30 }, 'c'); + expectRangedValuesItem (intersections.getItem (0), { 5, 10 }, 'a'); + expectRangedValuesItem (intersections.getItem (1), { 11, 20 }, 'b'); + expectRangedValuesItem (intersections.getItem (2), { 23, 30 }, 'c'); } { const auto intersections = rangedValues.getIntersectionsWith ({ -10, 3 }); - expectRangedValuesItem (intersections[0], { 0, 3 }, 'a'); + expectRangedValuesItem (intersections.getItem (0), { 0, 3 }, 'a'); } } diff --git a/modules/juce_graphics/detail/juce_Ranges.h b/modules/juce_graphics/detail/juce_Ranges.h index e5f8515e18..ab8c8e7279 100644 --- a/modules/juce_graphics/detail/juce_Ranges.h +++ b/modules/juce_graphics/detail/juce_Ranges.h @@ -784,18 +784,17 @@ public: /* Returns the stored values together with the overlapping range, that overlap with the provided range. */ - std::vector getIntersectionsWith (Range r) const + RangedValues getIntersectionsWith (Range r) const { const auto intersections = ranges.getIntersectionsWith (r); - std::vector result; - result.reserve (intersections.size()); + RangedValues result; for (const auto& is : intersections) { auto valueIndex = ranges.getIndexForEnclosingRange (is.getStart()); jassert (valueIndex.has_value()); - result.push_back ({ is, values[*valueIndex] }); + result.template set (is, values[*valueIndex]); } return result; diff --git a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp index 2b115a4d2f..c68a5f986c 100644 --- a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp @@ -832,7 +832,7 @@ struct Shaper const auto bidiLength = (int64) std::distance (it, next); const auto bidiRange = Range::withStartAndLength (bidiStart, bidiLength); - for (const auto& [range, font] : fonts.getIntersectionsWith (bidiRange)) + for (const auto [range, font] : fonts.getIntersectionsWith (bidiRange)) { shaperRuns.set (range, { scriptRun->front().script, diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 58bf43d440..50b42300ea 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -367,7 +367,7 @@ static MaxFontAscentAndDescent getMaxFontAscentAndDescentInEnclosingLine (const MaxFontAscentAndDescent result; - for (const auto& pair : fonts) + for (const auto pair : fonts) { result.ascent = std::max (result.ascent, pair.value.getAscent()); result.descent = std::max (result.descent, pair.value.getDescent());