Commit e1ea18bdb6e22d2521987708dca367eb5240ce8c

Authored by m-holger
1 parent 0d48b0e6

Tune JSON::JSON_string

Remove member encoded and encode strings only when required.

Encoded is only used when writing JSON. Since most JSON writing is now
done on the fly without creating a JSON representation, creating and
storing the encoded string in almost all cases no longer serves any
purpose.
include/qpdf/JSON.hh
@@ -329,7 +329,6 @@ class JSON @@ -329,7 +329,6 @@ class JSON
329 ~JSON_string() override = default; 329 ~JSON_string() override = default;
330 void write(Pipeline*, size_t depth) const override; 330 void write(Pipeline*, size_t depth) const override;
331 std::string utf8; 331 std::string utf8;
332 - std::string encoded;  
333 }; 332 };
334 struct JSON_number: public JSON_value 333 struct JSON_number: public JSON_value
335 { 334 {
libqpdf/JSON.cc
@@ -120,15 +120,14 @@ JSON::JSON_array::write(Pipeline* p, size_t depth) const @@ -120,15 +120,14 @@ JSON::JSON_array::write(Pipeline* p, size_t depth) const
120 120
121 JSON::JSON_string::JSON_string(std::string const& utf8) : 121 JSON::JSON_string::JSON_string(std::string const& utf8) :
122 JSON_value(vt_string), 122 JSON_value(vt_string),
123 - utf8(utf8),  
124 - encoded(Writer::encode_string(utf8)) 123 + utf8(utf8)
125 { 124 {
126 } 125 }
127 126
128 void 127 void
129 JSON::JSON_string::write(Pipeline* p, size_t) const 128 JSON::JSON_string::write(Pipeline* p, size_t) const
130 { 129 {
131 - *p << std::string("\"") + encoded + "\""; 130 + *p << std::string("\"") + Writer::encode_string(utf8) + "\"";
132 } 131 }
133 132
134 JSON::JSON_number::JSON_number(long long value) : 133 JSON::JSON_number::JSON_number(long long value) :