optimize toAscii function with early exit

GCC is able to see that the branch is useless as it can be done at
compile time. Produces shorter assembly with both -O2 and -O3.

https://godbolt.org/z/ejhfxh8Tx

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 2 years ago
parent c686bed5f8
commit 7473b4a715

@ -100,8 +100,9 @@ Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, m
// Obtains the ascii version from the box.type
std::string Jp2Image::toAscii(uint32_t n) {
const auto p = reinterpret_cast<const char*>(&n);
if (isBigEndianPlatform())
return std::string(p, p + 4);
std::string result(p, p + 4);
if (!isBigEndianPlatform())
std::reverse(result.begin(), result.end());
return result;
}

Loading…
Cancel
Save