From 56f9ee2b40c1b060d96a612f8cb782ab0c1947e6 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 13 Oct 2024 18:26:47 -0600 Subject: [PATCH] Remove unnecessary `static_cast`s --- src/SFML/Graphics/Font.cpp | 2 +- src/SFML/Graphics/Image.cpp | 2 +- src/SFML/Graphics/Shader.cpp | 2 +- src/SFML/Window/Unix/CursorImpl.cpp | 2 +- src/SFML/Window/Unix/WindowImplX11.cpp | 7 +++---- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 8dda58b63..609b0becf 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -608,7 +608,7 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool glyph.bounds.size = Vector2f(Vector2u(bitmap.width, bitmap.rows)); // Resize the pixel buffer to the new size and fill it with transparent white pixels - m_pixelBuffer.resize(static_cast(size.x) * static_cast(size.y) * 4); + m_pixelBuffer.resize(std::size_t{size.x} * std::size_t{size.y} * 4); std::uint8_t* current = m_pixelBuffer.data(); std::uint8_t* end = current + size.x * size.y * 4; diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index af6770392..8271acc29 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -141,7 +141,7 @@ void Image::resize(Vector2u size, Color color) if (size.x && size.y) { // Create a new pixel buffer first for exception safety's sake - std::vector newPixels(static_cast(size.x) * static_cast(size.y) * 4); + std::vector newPixels(std::size_t{size.x} * std::size_t{size.y} * 4); // Fill it with the specified color std::uint8_t* ptr = newPixels.data(); diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index a3beebb34..904da94c7 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -53,7 +53,7 @@ #if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) -#define castToGlHandle(x) reinterpret_cast(static_cast(x)) +#define castToGlHandle(x) reinterpret_cast(std::ptrdiff_t{x}) #define castFromGlHandle(x) static_cast(reinterpret_cast(x)) #else diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index e8cc13f2d..f4513ba6b 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -83,7 +83,7 @@ bool CursorImpl::loadFromPixelsARGB(const std::uint8_t* pixels, Vector2u size, V cursorImage->xhot = hotspot.x; cursorImage->yhot = hotspot.y; - const std::size_t numPixels = static_cast(size.x) * static_cast(size.y); + const std::size_t numPixels = std::size_t{size.x} * std::size_t{size.y}; for (std::size_t pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { cursorImage->pixels[pixelIndex] = static_cast( diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 03adf679d..93b135c7d 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -974,10 +974,9 @@ void WindowImplX11::setIcon(Vector2u size, const std::uint8_t* pixels) // X11 wants BGRA pixels: swap red and blue channels // Note: this memory will be freed by X11Ptr deleter // NOLINTBEGIN(cppcoreguidelines-no-malloc) - auto* iconPixels = static_cast( - std::malloc(static_cast(size.x) * static_cast(size.y) * 4)); + auto* iconPixels = static_cast(std::malloc(std::size_t{size.x} * std::size_t{size.y} * 4)); // NOLINTEND(cppcoreguidelines-no-malloc) - for (std::size_t i = 0; i < static_cast(size.x) * static_cast(size.y); ++i) + for (std::size_t i = 0; i < std::size_t{size.x} * std::size_t{size.y}; ++i) { iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; iconPixels[i * 4 + 1] = pixels[i * 4 + 1]; @@ -1052,7 +1051,7 @@ void WindowImplX11::setIcon(Vector2u size, const std::uint8_t* pixels) *ptr++ = size.y; #pragma GCC diagnostic pop - for (std::size_t i = 0; i < static_cast(size.x) * static_cast(size.y); ++i) + for (std::size_t i = 0; i < std::size_t{size.x} * std::size_t{size.y}; ++i) { *ptr++ = static_cast( (pixels[i * 4 + 2] << 0) | (pixels[i * 4 + 1] << 8) | (pixels[i * 4 + 0] << 16) | (pixels[i * 4 + 3] << 24));