1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

LibPDF: Get rid of PlainText/Encoded StreamObject

This was a small optimization to allow a stream object to simply hold
a reference to the bytes in a PDF document rather than duplicating
them. However, as we move into features such as encryption, this
optimization does more harm than good. This can be revisited in the
future if necessary.
This commit is contained in:
Matthew Olsson 2022-03-20 11:07:47 -07:00 committed by Andreas Kling
parent 15b7999313
commit c98bda8ce6
3 changed files with 6 additions and 40 deletions

View file

@ -143,55 +143,24 @@ private:
class StreamObject : public Object {
public:
explicit StreamObject(NonnullRefPtr<DictObject> const& dict)
explicit StreamObject(NonnullRefPtr<DictObject> const& dict, ByteBuffer const& bytes)
: m_dict(dict)
, m_buffer(bytes)
{
}
virtual ~StreamObject() override = default;
[[nodiscard]] ALWAYS_INLINE NonnullRefPtr<DictObject> dict() const { return m_dict; }
[[nodiscard]] virtual ReadonlyBytes bytes() const = 0;
[[nodiscard]] ReadonlyBytes bytes() const { return m_buffer.bytes(); };
const char* type_name() const override { return "stream"; }
String to_string(int indent) const override;
protected:
private:
bool is_stream() const override { return true; }
private:
NonnullRefPtr<DictObject> m_dict;
};
class PlainTextStreamObject final : public StreamObject {
public:
PlainTextStreamObject(NonnullRefPtr<DictObject> const& dict, ReadonlyBytes bytes)
: StreamObject(dict)
, m_bytes(bytes)
{
}
virtual ~PlainTextStreamObject() override = default;
[[nodiscard]] ALWAYS_INLINE virtual ReadonlyBytes bytes() const override { return m_bytes; }
private:
ReadonlyBytes m_bytes;
};
class EncodedStreamObject final : public StreamObject {
public:
EncodedStreamObject(NonnullRefPtr<DictObject> const& dict, ByteBuffer&& buffer)
: StreamObject(dict)
, m_buffer(buffer)
{
}
virtual ~EncodedStreamObject() override = default;
[[nodiscard]] ALWAYS_INLINE virtual ReadonlyBytes bytes() const override { return m_buffer.bytes(); }
private:
ByteBuffer m_buffer;
};