Commit 8a6b35827fb57b5ed72a695de713c668a268060d
1 parent
c436f035
Refactor `QPDF_Stream` and related classes to replace `Buffer` usage with `std::…
…string`, improving performance, simplifying stream data handling, and reducing dependency on `BufferInputSource`.
Showing
3 changed files
with
25 additions
and
27 deletions
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | #include <qpdf/ContentNormalizer.hh> |
| 4 | 4 | #include <qpdf/JSON_writer.hh> |
| 5 | 5 | #include <qpdf/Pipeline.hh> |
| 6 | +#include <qpdf/Pipeline_private.hh> | |
| 6 | 7 | #include <qpdf/Pl_Base64.hh> |
| 7 | 8 | #include <qpdf/Pl_Buffer.hh> |
| 8 | 9 | #include <qpdf/Pl_Count.hh> |
| ... | ... | @@ -319,10 +320,11 @@ qpdf::Stream::setDictDescription() |
| 319 | 320 | } |
| 320 | 321 | } |
| 321 | 322 | |
| 322 | -std::shared_ptr<Buffer> | |
| 323 | +std::string | |
| 323 | 324 | Stream::getStreamData(qpdf_stream_decode_level_e decode_level) |
| 324 | 325 | { |
| 325 | - Pl_Buffer buf("stream data buffer"); | |
| 326 | + std::string result; | |
| 327 | + pl::String buf(result); | |
| 326 | 328 | bool filtered; |
| 327 | 329 | pipeStreamData(&buf, &filtered, 0, decode_level, false, false); |
| 328 | 330 | if (!filtered) { |
| ... | ... | @@ -334,13 +336,14 @@ Stream::getStreamData(qpdf_stream_decode_level_e decode_level) |
| 334 | 336 | "getStreamData called on unfilterable stream"); |
| 335 | 337 | } |
| 336 | 338 | QTC::TC("qpdf", "QPDF_Stream getStreamData"); |
| 337 | - return buf.getBufferSharedPointer(); | |
| 339 | + return result; | |
| 338 | 340 | } |
| 339 | 341 | |
| 340 | -std::shared_ptr<Buffer> | |
| 342 | +std::string | |
| 341 | 343 | Stream::getRawStreamData() |
| 342 | 344 | { |
| 343 | - Pl_Buffer buf("stream data buffer"); | |
| 345 | + std::string result; | |
| 346 | + pl::String buf(result); | |
| 344 | 347 | if (!pipeStreamData(&buf, nullptr, 0, qpdf_dl_none, false, false)) { |
| 345 | 348 | throw QPDFExc( |
| 346 | 349 | qpdf_e_unsupported, |
| ... | ... | @@ -350,7 +353,7 @@ Stream::getRawStreamData() |
| 350 | 353 | "error getting raw stream data"); |
| 351 | 354 | } |
| 352 | 355 | QTC::TC("qpdf", "QPDF_Stream getRawStreamData"); |
| 353 | - return buf.getBufferSharedPointer(); | |
| 356 | + return result; | |
| 354 | 357 | } |
| 355 | 358 | |
| 356 | 359 | bool |
| ... | ... | @@ -683,13 +686,13 @@ QPDFObjectHandle::isRootMetadata() const |
| 683 | 686 | std::shared_ptr<Buffer> |
| 684 | 687 | QPDFObjectHandle::getStreamData(qpdf_stream_decode_level_e level) |
| 685 | 688 | { |
| 686 | - return as_stream(error).getStreamData(level); | |
| 689 | + return std::make_shared<Buffer>(as_stream(error).getStreamData(level)); | |
| 687 | 690 | } |
| 688 | 691 | |
| 689 | 692 | std::shared_ptr<Buffer> |
| 690 | 693 | QPDFObjectHandle::getRawStreamData() |
| 691 | 694 | { |
| 692 | - return as_stream(error).getRawStreamData(); | |
| 695 | + return std::make_shared<Buffer>(as_stream(error).getRawStreamData()); | |
| 693 | 696 | } |
| 694 | 697 | |
| 695 | 698 | bool | ... | ... |
libqpdf/QPDF_objects.cc
| ... | ... | @@ -2,18 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | #include <qpdf/QPDF_private.hh> |
| 4 | 4 | |
| 5 | -#include <array> | |
| 6 | -#include <atomic> | |
| 7 | -#include <cstring> | |
| 8 | -#include <limits> | |
| 9 | -#include <map> | |
| 10 | -#include <regex> | |
| 11 | -#include <sstream> | |
| 12 | -#include <vector> | |
| 13 | - | |
| 14 | -#include <qpdf/BufferInputSource.hh> | |
| 15 | 5 | #include <qpdf/InputSource_private.hh> |
| 16 | -#include <qpdf/OffsetInputSource.hh> | |
| 17 | 6 | #include <qpdf/Pipeline.hh> |
| 18 | 7 | #include <qpdf/QPDFExc.hh> |
| 19 | 8 | #include <qpdf/QPDFLogger.hh> |
| ... | ... | @@ -24,6 +13,13 @@ |
| 24 | 13 | #include <qpdf/QUtil.hh> |
| 25 | 14 | #include <qpdf/Util.hh> |
| 26 | 15 | |
| 16 | +#include <array> | |
| 17 | +#include <atomic> | |
| 18 | +#include <cstring> | |
| 19 | +#include <limits> | |
| 20 | +#include <map> | |
| 21 | +#include <vector> | |
| 22 | + | |
| 27 | 23 | using namespace qpdf; |
| 28 | 24 | using namespace std::literals; |
| 29 | 25 | |
| ... | ... | @@ -1675,13 +1671,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number) |
| 1675 | 1671 | // id, offset, size |
| 1676 | 1672 | std::vector<std::tuple<int, qpdf_offset_t, size_t>> offsets; |
| 1677 | 1673 | |
| 1678 | - auto bp = obj_stream.getStreamData(qpdf_dl_specialized); | |
| 1674 | + auto stream_data = obj_stream.getStreamData(qpdf_dl_specialized); | |
| 1679 | 1675 | |
| 1680 | - BufferInputSource input("", bp.get()); | |
| 1676 | + is::OffsetBuffer input("", stream_data); | |
| 1681 | 1677 | |
| 1682 | - const auto b_size = bp->getSize(); | |
| 1678 | + const auto b_size = stream_data.size(); | |
| 1683 | 1679 | const auto end_offset = static_cast<qpdf_offset_t>(b_size); |
| 1684 | - auto b_start = bp->getBuffer(); | |
| 1680 | + auto b_start = stream_data.data(); | |
| 1685 | 1681 | |
| 1686 | 1682 | if (first >= end_offset) { |
| 1687 | 1683 | throw damagedPDF( |
| ... | ... | @@ -1762,8 +1758,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) |
| 1762 | 1758 | auto entry = m->xref_table.find(og); |
| 1763 | 1759 | if (entry != m->xref_table.end() && entry->second.getType() == 2 && |
| 1764 | 1760 | entry->second.getObjStreamNumber() == obj_stream_number) { |
| 1765 | - Buffer obj_buffer{b_start + obj_offset, obj_size}; | |
| 1766 | - is::OffsetBuffer in("", &obj_buffer, obj_offset); | |
| 1761 | + is::OffsetBuffer in("", {b_start + obj_offset, obj_size}, obj_offset); | |
| 1767 | 1762 | auto oh = readObjectInStream(in, obj_stream_number, obj_id); |
| 1768 | 1763 | updateCache(og, oh.getObj(), end_before_space, end_after_space); |
| 1769 | 1764 | } else { | ... | ... |
libqpdf/qpdf/QPDFObjectHandle_private.hh
| ... | ... | @@ -254,8 +254,8 @@ namespace qpdf |
| 254 | 254 | qpdf_stream_decode_level_e decode_level, |
| 255 | 255 | bool suppress_warnings, |
| 256 | 256 | bool will_retry); |
| 257 | - std::shared_ptr<Buffer> getStreamData(qpdf_stream_decode_level_e level); | |
| 258 | - std::shared_ptr<Buffer> getRawStreamData(); | |
| 257 | + std::string getStreamData(qpdf_stream_decode_level_e level); | |
| 258 | + std::string getRawStreamData(); | |
| 259 | 259 | void replaceStreamData( |
| 260 | 260 | std::shared_ptr<Buffer> data, |
| 261 | 261 | QPDFObjectHandle const& filter, | ... | ... |