From d5a1edba09f95b868c03879a4c05ffef9a3d80d8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 27 Mar 2018 12:16:08 -0400 Subject: [PATCH 1/2] HiresTextures: Remove unnecessary pointer casts in GenBaseName() swap16 has an overload that accepts a u8*, performing the same behavior in a well-defined manner. --- Source/Core/VideoCommon/HiresTextures.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 6362636387..9df399365f 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -243,10 +243,11 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co } break; case 16384 * 2: - for (size_t i = 0; i < texture_size / 2; i++) + for (size_t i = 0; i < texture_size; i += sizeof(u16)) { - min = std::min(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); - max = std::max(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); + const u16 texture_halfword = Common::swap16(texture[i]) & 0x3fff; + min = std::min(min, texture_halfword); + max = std::max(max, texture_halfword); } break; } From 2da8d98b2f94a33e337d37dc7153e5ba445961f3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 27 Mar 2018 12:37:04 -0400 Subject: [PATCH 2/2] HiresTextures: Use std::minmax or std::minmax_element where applicable in GenBaseName() Minimizes repetition. std::minmax_element can be used for the 256 * 2 case, as it's only performing byte comparisons and thus, there will always be an element smaller than 0xffff, so it doesn't need to be included in the set of compared values. --- Source/Core/VideoCommon/HiresTextures.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 9df399365f..c74b4e617d 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -229,25 +230,23 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co case 16 * 2: for (size_t i = 0; i < texture_size; i++) { - min = std::min(min, texture[i] & 0xf); - min = std::min(min, texture[i] >> 4); - max = std::max(max, texture[i] & 0xf); - max = std::max(max, texture[i] >> 4); + const u32 low_nibble = texture[i] & 0xf; + const u32 high_nibble = texture[i] >> 4; + std::tie(min, max) = std::minmax({min, max, low_nibble, high_nibble}); } break; case 256 * 2: - for (size_t i = 0; i < texture_size; i++) - { - min = std::min(min, texture[i]); - max = std::max(max, texture[i]); - } + { + const auto minmax = std::minmax_element(texture, texture + texture_size); + min = *minmax.first; + max = *minmax.second; break; + } case 16384 * 2: for (size_t i = 0; i < texture_size; i += sizeof(u16)) { - const u16 texture_halfword = Common::swap16(texture[i]) & 0x3fff; - min = std::min(min, texture_halfword); - max = std::max(max, texture_halfword); + const u32 texture_halfword = Common::swap16(texture[i]) & 0x3fff; + std::tie(min, max) = std::minmax({min, max, texture_halfword}); } break; }