From b939c794fbd095e47e45a292d4a1e3dedbf7a808 Mon Sep 17 00:00:00 2001 From: vfjpl Date: Wed, 9 Dec 2020 14:41:54 +0100 Subject: [PATCH] Don't needlesly call getSize() twice while setting texture --- src/SFML/Graphics/Sprite.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 145c48bd7..6a23258c9 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -55,7 +55,9 @@ Sprite::Sprite(const Texture& texture, const IntRect& rectangle) : m_texture (NULL), m_textureRect() { + // Compute the texture area setTextureRect(rectangle); + // Assign texture setTexture(texture, false); } @@ -65,7 +67,10 @@ void Sprite::setTexture(const Texture& texture, bool resetRect) { // Recompute the texture area if requested, or if there was no valid texture & rect before if (resetRect || (!m_texture && (m_textureRect == sf::IntRect()))) - setTextureRect(IntRect(0, 0, texture.getSize().x, texture.getSize().y)); + { + Vector2u size = texture.getSize(); + setTextureRect(IntRect(0, 0, size.x, size.y)); + } // Assign the new texture m_texture = &texture;