Improve code

This commit is contained in:
Lynix 2020-07-31 12:36:37 +02:00
parent 2271432748
commit 10860ed562
2 changed files with 6 additions and 14 deletions

View File

@ -49,7 +49,7 @@ namespace Nz
inline unsigned int SpirvWriter::CountWord(const std::string_view& str)
{
return (str.size() + 1 + 4 - 1) / 4; //< + 1 for null character
return (static_cast<unsigned int>(str.size() + 1) + sizeof(UInt32) - 1) / sizeof(UInt32); //< + 1 for null character
}
}

View File

@ -40,10 +40,6 @@ namespace Nz
AppendHeader();
// OpImageSampleImplicitLod %23 %31 %35
//Append("BONJOUR PRAETONUS");
std::vector<UInt32> ret = std::move(state.output);
return ret;
}
@ -58,17 +54,13 @@ namespace Nz
std::size_t size4 = CountWord(str);
for (std::size_t i = 0; i < size4; ++i)
{
auto GetChar = [&](std::size_t pos) -> UInt32
{
if (pos < str.size())
return static_cast<UInt32>(str[pos]);
else
return 0;
};
UInt32 codepoint = 0;
for (std::size_t j = 0; j < 4; ++j)
codepoint |= GetChar(i * 4 + j) << (j * 8);
{
std::size_t pos = i * 4 + j;
if (pos < str.size())
codepoint |= UInt32(str[pos]) << (j * 8);
}
Append(codepoint);
}