diff --git a/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h b/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h index efc704466f..ef9e87772c 100644 --- a/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h +++ b/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h @@ -99,6 +99,7 @@ private: int samplesAgo = (nextSample + numElementsInArray (samples) - 1); RectangleList waveform; + waveform.ensureStorageAllocated ((int) numElementsInArray (samples)); for (int x = jmin (getWidth(), (int) numElementsInArray (samples)); --x >= 0;) { diff --git a/extras/Demo/Source/Demos/GraphicsDemo.cpp b/extras/Demo/Source/Demos/GraphicsDemo.cpp index 8e20d1f2f5..07a631b230 100644 --- a/extras/Demo/Source/Demos/GraphicsDemo.cpp +++ b/extras/Demo/Source/Demos/GraphicsDemo.cpp @@ -508,6 +508,8 @@ public: { { RectangleList verticalLines; + verticalLines.ensureStorageAllocated (getWidth()); + float pos = offset.getValue(); for (int x = 0; x < getWidth(); ++x) @@ -523,6 +525,8 @@ public: { RectangleList horizontalLines; + horizontalLines.ensureStorageAllocated (getHeight()); + float pos = offset.getValue(); for (int y = 0; y < getHeight(); ++y) diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp index f5cf5d6c6a..3a155b07d6 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp @@ -391,6 +391,7 @@ public: const MinMaxValue* cacheData = getData (channelNum, clip.getX() - area.getX()); RectangleList waveform; + waveform.ensureStorageAllocated (clip.getWidth()); float x = (float) clip.getX(); diff --git a/modules/juce_graphics/geometry/juce_RectangleList.h b/modules/juce_graphics/geometry/juce_RectangleList.h index 3637f6ad11..f1b81a74ac 100644 --- a/modules/juce_graphics/geometry/juce_RectangleList.h +++ b/modules/juce_graphics/geometry/juce_RectangleList.h @@ -628,6 +628,17 @@ public: /** Standard method for iterating the rectangles in the list. */ const RectangleType* end() const noexcept { return rects.end(); } + /** Increases the internal storage to hold a minimum number of rectangles. + Calling this before adding a large number of rectangles means that + the array won't have to keep dynamically resizing itself as the elements + are added, and it'll therefore be more efficient. + @see Array::ensureStorageAllocated + */ + void ensureStorageAllocated (int minNumRectangles) + { + rects.ensureStorageAllocated (minNumRectangles); + } + private: //============================================================================== Array rects; diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 31fc932456..32f1c26576 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -1222,6 +1222,8 @@ private: const Rectangle clipBounds (clipW, clipH); const CGFloat viewH = [view frame].size.height; + clip.ensureStorageAllocated ((int) numRects); + for (int i = 0; i < numRects; ++i) clip.addWithoutMerging (clipBounds.getIntersection (Rectangle (roundToInt (rects[i].origin.x) + offset.x, roundToInt (viewH - (rects[i].origin.y + rects[i].size.height)) + offset.y,