Commit 1e53da74bc3cf0cbd3bd3dae2890e83ad33c3ed4
Committed by
GitHub
Merge pull request #918 from m-holger/fixqdf
Code tidy QdfFixer methods
Showing
1 changed file
with
8 additions
and
15 deletions
qpdf/fix-qdf.cc
| ... | ... | @@ -316,21 +316,18 @@ QdfFixer::processLines(std::string const& input) |
| 316 | 316 | void |
| 317 | 317 | QdfFixer::checkObjId(std::string const& cur_obj_str) |
| 318 | 318 | { |
| 319 | - int cur_obj = QUtil::string_to_int(cur_obj_str.c_str()); | |
| 320 | - if (cur_obj != last_obj + 1) { | |
| 319 | + if (std::stoi(cur_obj_str) != ++last_obj) { | |
| 321 | 320 | fatal( |
| 322 | 321 | filename + ":" + std::to_string(lineno) + ": expected object " + |
| 323 | - std::to_string(last_obj + 1)); | |
| 322 | + std::to_string(last_obj)); | |
| 324 | 323 | } |
| 325 | - last_obj = cur_obj; | |
| 326 | - xref.push_back(QPDFXRefEntry(1, QIntC::to_offset(last_offset), 0)); | |
| 324 | + xref.push_back(QPDFXRefEntry(1, last_offset, 0)); | |
| 327 | 325 | } |
| 328 | 326 | |
| 329 | 327 | void |
| 330 | 328 | QdfFixer::adjustOstreamXref() |
| 331 | 329 | { |
| 332 | - xref.pop_back(); | |
| 333 | - xref.push_back(QPDFXRefEntry(2, ostream_id, QIntC::to_int(ostream_idx++))); | |
| 330 | + xref.back() = QPDFXRefEntry(2, ostream_id, QIntC::to_int(ostream_idx++)); | |
| 334 | 331 | } |
| 335 | 332 | |
| 336 | 333 | void |
| ... | ... | @@ -382,14 +379,10 @@ QdfFixer::writeBinary(unsigned long long val, size_t bytes) |
| 382 | 379 | throw std::logic_error( |
| 383 | 380 | "fix-qdf::writeBinary called with too many bytes"); |
| 384 | 381 | } |
| 385 | - std::string data; | |
| 386 | - data.reserve(bytes); | |
| 387 | - for (size_t i = 0; i < bytes; ++i) { | |
| 388 | - data.append(1, '\0'); | |
| 389 | - } | |
| 390 | - for (size_t i = 0; i < bytes; ++i) { | |
| 391 | - data.at(bytes - i - 1) = static_cast<char>(QIntC::to_uchar(val & 0xff)); | |
| 392 | - val >>= 8; | |
| 382 | + std::string data(bytes, '\0'); | |
| 383 | + for (auto i = bytes; i > 0; --i) { | |
| 384 | + data[i - 1] = static_cast<char>(val & 0xff); // i.e. val % 256 | |
| 385 | + val >>= 8; // i.e. val = val / 256 | |
| 393 | 386 | } |
| 394 | 387 | std::cout << data; |
| 395 | 388 | } | ... | ... |