From 1a2188e898ad8f07b7bb223d0f49df0a616a85b9 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Thu, 27 Mar 2025 20:03:35 -0700 Subject: [PATCH] Precompute values & reserve memory in CreateFrameRects() Reduce the number of calculations in nested loops, and reserve the needed amount of memory instead of relying on the vector to resize itself. --- src/RageTexture.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/RageTexture.cpp b/src/RageTexture.cpp index 39e2766280..1753902fa5 100644 --- a/src/RageTexture.cpp +++ b/src/RageTexture.cpp @@ -28,15 +28,22 @@ void RageTexture::CreateFrameRects() // Fill in the m_FrameRects with the bounds of each frame in the animation. m_TextureCoordRects.clear(); + m_TextureCoordRects.reserve(static_cast(m_iFramesWide * m_iFramesHigh)); + + float frameWidth = (m_iImageWidth / static_cast(m_iTextureWidth)) / m_iFramesWide; + float frameHeight = (m_iImageHeight / static_cast(m_iTextureHeight)) / m_iFramesHigh; for( int j=0; jTrace( "Adding frect%d %f %f %f %f", (i + j*m_iFramesWide), frect.left, frect.top, frect.right, frect.bottom );