Commit 29cd8f4f53dcad517ecba37978d6073daf43d819

Authored by m-holger
1 parent 81823f40

Avoid unnecessary string copies in QPDFParser::parse

Fixes #864. QPDFTokenizer::getValue originally had a std::string_view
return type, which was changed to std::string without removing some
unnecessary string creation.
Showing 1 changed file with 4 additions and 5 deletions
libqpdf/QPDFParser.cc
... ... @@ -156,8 +156,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
156 156 break;
157 157  
158 158 case QPDFTokenizer::tt_integer:
159   - object = QPDF_Integer::create(
160   - QUtil::string_to_ll(std::string(tokenizer.getValue()).c_str()));
  159 + object = QPDF_Integer::create(QUtil::string_to_ll(tokenizer.getValue().c_str()));
161 160 break;
162 161  
163 162 case QPDFTokenizer::tt_real:
... ... @@ -166,7 +165,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
166 165  
167 166 case QPDFTokenizer::tt_name:
168 167 {
169   - auto name = tokenizer.getValue();
  168 + auto const& name = tokenizer.getValue();
170 169 object = QPDF_Name::create(name);
171 170  
172 171 if (name == "/Contents") {
... ... @@ -179,7 +178,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
179 178  
180 179 case QPDFTokenizer::tt_word:
181 180 {
182   - auto value = tokenizer.getValue();
  181 + auto const& value = tokenizer.getValue();
183 182 auto size = olist.size();
184 183 if (content_stream) {
185 184 object = QPDF_Operator::create(value);
... ... @@ -226,7 +225,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
226 225  
227 226 case QPDFTokenizer::tt_string:
228 227 {
229   - auto val = tokenizer.getValue();
  228 + auto const& val = tokenizer.getValue();
230 229 if (decrypter) {
231 230 if (b_contents) {
232 231 frame.contents_string = val;
... ...