From 77a78511c6c042e31c2f903a08bf06319b491c82 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sat, 11 Apr 2015 14:04:44 -0700 Subject: [PATCH] Add a few assumptions for performance --- PVRTCEncoder/src/Indexer.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/PVRTCEncoder/src/Indexer.h b/PVRTCEncoder/src/Indexer.h index d04a980..da4537b 100644 --- a/PVRTCEncoder/src/Indexer.h +++ b/PVRTCEncoder/src/Indexer.h @@ -67,18 +67,27 @@ class Indexer { const uint32 m_Height; uint32 Resolve(int32 i, uint32 limit) const { + int32 l = static_cast(limit); + + // Assumptions + assert(i > -l); + assert(i < 2*l); + int32 r; switch(m_WrapMode) { case eWrapMode_Clamp: - r = static_cast(std::max(0, std::min(i, limit))); + r = static_cast(std::max(0, std::min(i, l))); break; case eWrapMode_Wrap: { r = i; - int32 l = static_cast(limit); - while (r >= l) { r -= l; } - while (r < 0) { r += l; } + if ((l & (l-1)) == 0) { + r = (r + l) & (l - 1); + } else { + if (r >= l) { r -= l; } + if (r < 0) { r += l; } + } } break; }