Commit cf945eeabfea822d5aeb7b1d860dbc3a4eeedfa3

Authored by m-holger
1 parent 45a6100c

Avoid shrinking QPDFTokenizer::val and QPDFTokenizer::raw_val

Showing 1 changed file with 11 additions and 8 deletions
libqpdf/QPDFTokenizer.cc
@@ -78,8 +78,8 @@ QPDFTokenizer::reset() @@ -78,8 +78,8 @@ QPDFTokenizer::reset()
78 { 78 {
79 state = st_top; 79 state = st_top;
80 type = tt_bad; 80 type = tt_bad;
81 - val = "";  
82 - raw_val = ""; 81 + val.clear();
  82 + raw_val.clear();
83 error_message = ""; 83 error_message = "";
84 unread_char = false; 84 unread_char = false;
85 char_to_unread = '\0'; 85 char_to_unread = '\0';
@@ -175,7 +175,8 @@ QPDFTokenizer::resolveLiteral() @@ -175,7 +175,8 @@ QPDFTokenizer::resolveLiteral()
175 nval.append(1, ch); 175 nval.append(1, ch);
176 } 176 }
177 } 177 }
178 - this->val = nval; 178 + this->val.clear();
  179 + this->val += nval;
179 } else if (QUtil::is_number(this->val.c_str())) { 180 } else if (QUtil::is_number(this->val.c_str())) {
180 if (this->val.find('.') != std::string::npos) { 181 if (this->val.find('.') != std::string::npos) {
181 this->type = tt_real; 182 this->type = tt_real;
@@ -282,7 +283,7 @@ QPDFTokenizer::presentCharacter(char ch) @@ -282,7 +283,7 @@ QPDFTokenizer::presentCharacter(char ch)
282 } 283 }
283 } else if (this->state == st_lt) { 284 } else if (this->state == st_lt) {
284 if (ch == '<') { 285 if (ch == '<') {
285 - this->val = "<<"; 286 + this->val += "<<";
286 this->type = tt_dict_open; 287 this->type = tt_dict_open;
287 this->state = st_token_ready; 288 this->state = st_token_ready;
288 } else { 289 } else {
@@ -291,11 +292,11 @@ QPDFTokenizer::presentCharacter(char ch) @@ -291,11 +292,11 @@ QPDFTokenizer::presentCharacter(char ch)
291 } 292 }
292 } else if (this->state == st_gt) { 293 } else if (this->state == st_gt) {
293 if (ch == '>') { 294 if (ch == '>') {
294 - this->val = ">>"; 295 + this->val += ">>";
295 this->type = tt_dict_close; 296 this->type = tt_dict_close;
296 this->state = st_token_ready; 297 this->state = st_token_ready;
297 } else { 298 } else {
298 - this->val = ">"; 299 + this->val += ">";
299 this->type = tt_bad; 300 this->type = tt_bad;
300 QTC::TC("qpdf", "QPDFTokenizer bad >"); 301 QTC::TC("qpdf", "QPDFTokenizer bad >");
301 this->error_message = "unexpected >"; 302 this->error_message = "unexpected >";
@@ -437,7 +438,8 @@ QPDFTokenizer::presentCharacter(char ch) @@ -437,7 +438,8 @@ QPDFTokenizer::presentCharacter(char ch)
437 char nch = static_cast<char>(strtol(num, nullptr, 16)); 438 char nch = static_cast<char>(strtol(num, nullptr, 16));
438 nval += nch; 439 nval += nch;
439 } 440 }
440 - this->val = nval; 441 + this->val.clear();
  442 + this->val += nval;
441 } else if (QUtil::is_hex_digit(ch)) { 443 } else if (QUtil::is_hex_digit(ch)) {
442 this->val += ch; 444 this->val += ch;
443 } else if (isSpace(ch)) { 445 } else if (isSpace(ch)) {
@@ -600,7 +602,8 @@ QPDFTokenizer::getToken(Token&amp; token, bool&amp; unread_char, char&amp; ch) @@ -600,7 +602,8 @@ QPDFTokenizer::getToken(Token&amp; token, bool&amp; unread_char, char&amp; ch)
600 ch = this->char_to_unread; 602 ch = this->char_to_unread;
601 if (ready) { 603 if (ready) {
602 if (this->type == tt_bad) { 604 if (this->type == tt_bad) {
603 - this->val = this->raw_val; 605 + this->val.clear();
  606 + this->val += this->raw_val;
604 } 607 }
605 token = 608 token =
606 Token(this->type, this->val, this->raw_val, this->error_message); 609 Token(this->type, this->val, this->raw_val, this->error_message);