VideoCommon/IndexGenerator: Make use of if constexpr

We can use if constexpr with the template functions that pass in a
non-type template parameter, allowing the removal of branches that
aren't taken at compile time.

Compilers will generally do this by default, however, we now give a
gentle prodding to the compiler if this would otherwise not be the case.
This commit is contained in:
Lioncash 2019-12-05 09:52:16 -05:00
parent fb3fda775f
commit 159947ab68
1 changed files with 4 additions and 4 deletions

View File

@ -26,7 +26,7 @@ u16* WriteTriangle(u16* index_ptr, u32 index1, u32 index2, u32 index3)
*index_ptr++ = index1; *index_ptr++ = index1;
*index_ptr++ = index2; *index_ptr++ = index2;
*index_ptr++ = index3; *index_ptr++ = index3;
if (pr) if constexpr (pr)
*index_ptr++ = s_primitive_restart; *index_ptr++ = s_primitive_restart;
return index_ptr; return index_ptr;
} }
@ -44,7 +44,7 @@ u16* AddList(u16* index_ptr, u32 num_verts, u32 index)
template <bool pr> template <bool pr>
u16* AddStrip(u16* index_ptr, u32 num_verts, u32 index) u16* AddStrip(u16* index_ptr, u32 num_verts, u32 index)
{ {
if (pr) if constexpr (pr)
{ {
for (u32 i = 0; i < num_verts; ++i) for (u32 i = 0; i < num_verts; ++i)
{ {
@ -89,7 +89,7 @@ u16* AddFan(u16* index_ptr, u32 num_verts, u32 index)
{ {
u32 i = 2; u32 i = 2;
if (pr) if constexpr (pr)
{ {
for (; i + 3 <= num_verts; i += 3) for (; i + 3 <= num_verts; i += 3)
{ {
@ -141,7 +141,7 @@ u16* AddQuads(u16* index_ptr, u32 num_verts, u32 index)
u32 i = 3; u32 i = 3;
for (; i < num_verts; i += 4) for (; i < num_verts; i += 4)
{ {
if (pr) if constexpr (pr)
{ {
*index_ptr++ = index + i - 2; *index_ptr++ = index + i - 2;
*index_ptr++ = index + i - 1; *index_ptr++ = index + i - 1;