Commit 71bba5d40dcbeac5bd2741ca155c111d9a3ee47b

Authored by m-holger
1 parent b27be3ed

Code tidy QdfFixer::writeBinary

Showing 1 changed file with 4 additions and 8 deletions
qpdf/fix-qdf.cc
... ... @@ -363,14 +363,10 @@ QdfFixer::writeBinary(unsigned long long val, size_t bytes)
363 363 throw std::logic_error(
364 364 "fix-qdf::writeBinary called with too many bytes");
365 365 }
366   - std::string data;
367   - data.reserve(bytes);
368   - for (size_t i = 0; i < bytes; ++i) {
369   - data.append(1, '\0');
370   - }
371   - for (size_t i = 0; i < bytes; ++i) {
372   - data.at(bytes - i - 1) = static_cast<char>(QIntC::to_uchar(val & 0xff));
373   - val >>= 8;
  366 + std::string data(bytes, '\0');
  367 + for (auto i = bytes; i > 0; --i) {
  368 + data[i - 1] = static_cast<char>(val & 0xff); // i.e. val % 256
  369 + val >>= 8; // i.e. val = val / 256
374 370 }
375 371 std::cout << data;
376 372 }
... ...