From badb3885075894169bcf2468d99c82ec4cc18793 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Wed, 14 Sep 2022 14:32:06 -0600 Subject: [PATCH] Remove unnecessary casts --- include/SFML/Graphics/Color.inl | 7 +++---- src/SFML/Audio/Music.cpp | 2 +- src/SFML/Graphics/Texture.cpp | 5 ++--- test/TestUtilities/GraphicsUtil.cpp | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/SFML/Graphics/Color.inl b/include/SFML/Graphics/Color.inl index 3cc2656c..cd156de7 100644 --- a/include/SFML/Graphics/Color.inl +++ b/include/SFML/Graphics/Color.inl @@ -73,7 +73,7 @@ constexpr Color operator+(const Color& left, const Color& right) { const auto clampedAdd = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t { - const int intResult = static_cast(lhs) + static_cast(rhs); + const int intResult = int{lhs} + int{rhs}; return static_cast(intResult < 255 ? intResult : 255); }; @@ -89,7 +89,7 @@ constexpr Color operator-(const Color& left, const Color& right) { const auto clampedSub = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t { - const int intResult = static_cast(lhs) - static_cast(rhs); + const int intResult = int{lhs} - int{rhs}; return static_cast(intResult > 0 ? intResult : 0); }; @@ -105,8 +105,7 @@ constexpr Color operator*(const Color& left, const Color& right) { const auto scaledMul = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t { - const auto uint16Result = static_cast( - static_cast(lhs) * static_cast(rhs)); + const auto uint16Result = static_cast(std::uint16_t{lhs} * std::uint16_t{rhs}); return static_cast(uint16Result / 255u); }; diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index c486cc96..5eb21826 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -238,7 +238,7 @@ void Music::initialize() m_loopSpan.length = m_file.getSampleCount(); // Resize the internal buffer so that it can contain 1 second of audio samples - m_samples.resize(static_cast(m_file.getSampleRate()) * static_cast(m_file.getChannelCount())); + m_samples.resize(m_file.getSampleRate() * m_file.getChannelCount()); // Initialize the stream SoundStream::initialize(m_file.getChannelCount(), m_file.getSampleRate()); diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index df6970d6..f84b3d59 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -331,7 +331,7 @@ Image Texture::copyToImage() const priv::TextureSaver save; // Create an array of pixels - std::vector pixels(static_cast(m_size.x) * static_cast(m_size.y) * 4); + std::vector pixels(m_size.x * m_size.y * 4); #ifdef SFML_OPENGL_ES @@ -365,8 +365,7 @@ Image Texture::copyToImage() const // Texture is either padded or flipped, we have to use a slower algorithm // All the pixels will first be copied to a temporary array - std::vector allPixels( - static_cast(m_actualSize.x) * static_cast(m_actualSize.y) * 4); + std::vector allPixels(m_actualSize.x * m_actualSize.y * 4); glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data())); diff --git a/test/TestUtilities/GraphicsUtil.cpp b/test/TestUtilities/GraphicsUtil.cpp index 7f36dcfb..10689554 100644 --- a/test/TestUtilities/GraphicsUtil.cpp +++ b/test/TestUtilities/GraphicsUtil.cpp @@ -16,9 +16,8 @@ std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode) std::ostream& operator<<(std::ostream& os, const Color& color) { - return os << "0x" << std::hex << color.toInteger() << std::dec << " (r=" << static_cast(color.r) - << ", g=" << static_cast(color.g) << ", b=" << static_cast(color.b) - << ", a=" << static_cast(color.a) << ")"; + return os << "0x" << std::hex << color.toInteger() << std::dec << " (r=" << int{color.r} << ", g=" << int{color.g} + << ", b=" << int{color.b} << ", a=" << int{color.a} << ")"; } std::ostream& operator<<(std::ostream& os, const Transform& transform)