Commit a07d2b4190bc0db778a254733dac88dccd5757fd

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 59191ebb

Only build QPDFTokenizer::val for name and string tokens

For all other token types val and raw_val are identical.
Showing 1 changed file with 4 additions and 37 deletions
libqpdf/QPDFTokenizer.cc
... ... @@ -261,15 +261,11 @@ QPDFTokenizer::inBeforeToken(char ch)
261 261 this->in_token = this->include_ignorable;
262 262 if (this->include_ignorable) {
263 263 this->state = st_in_space;
264   - this->val += ch;
265 264 }
266 265 } else if (ch == '%') {
267 266 this->before_token = !this->include_ignorable;
268 267 this->in_token = this->include_ignorable;
269 268 this->state = st_in_comment;
270   - if (this->include_ignorable) {
271   - this->val += ch;
272   - }
273 269 } else {
274 270 this->before_token = false;
275 271 this->in_token = true;
... ... @@ -298,32 +294,27 @@ QPDFTokenizer::inTop(char ch)
298 294 this->type = tt_bad;
299 295 QTC::TC("qpdf", "QPDFTokenizer bad )");
300 296 this->error_message = "unexpected )";
301   - this->val += ch;
302 297 this->state = st_token_ready;
303 298 return;
304 299  
305 300 case '[':
306 301 this->type = tt_array_open;
307 302 this->state = st_token_ready;
308   - this->val += ch;
309 303 return;
310 304  
311 305 case ']':
312 306 this->type = tt_array_close;
313   - this->val += ch;
314 307 this->state = st_token_ready;
315 308 return;
316 309  
317 310 case '{':
318 311 this->type = tt_brace_open;
319 312 this->state = st_token_ready;
320   - this->val += ch;
321 313 return;
322 314  
323 315 case '}':
324 316 this->type = tt_brace_close;
325 317 this->state = st_token_ready;
326   - this->val += ch;
327 318 return;
328 319  
329 320 case '/':
... ... @@ -342,23 +333,19 @@ QPDFTokenizer::inTop(char ch)
342 333 case '8':
343 334 case '9':
344 335 this->state = st_number;
345   - this->val += ch;
346 336 return;
347 337  
348 338 case '+':
349 339 case '-':
350 340 this->state = st_sign;
351   - this->val += ch;
352 341 return;
353 342  
354 343 case '.':
355 344 this->state = st_decimal;
356   - this->val += ch;
357 345 return;
358 346  
359 347 default:
360 348 this->state = st_literal;
361   - this->val += ch;
362 349 return;
363 350 }
364 351 }
... ... @@ -372,10 +359,6 @@ QPDFTokenizer::inSpace(char ch)
372 359 this->in_token = false;
373 360 this->char_to_unread = ch;
374 361 this->state = st_token_ready;
375   - return;
376   - } else {
377   - this->val += ch;
378   - return;
379 362 }
380 363 }
381 364  
... ... @@ -391,8 +374,6 @@ QPDFTokenizer::inComment(char ch)
391 374 } else {
392 375 this->state = st_before_token;
393 376 }
394   - } else if (this->include_ignorable) {
395   - this->val += ch;
396 377 }
397 378 }
398 379  
... ... @@ -527,10 +508,8 @@ QPDFTokenizer::inSign(char ch)
527 508 {
528 509 if (QUtil::is_digit(ch)) {
529 510 this->state = st_number;
530   - this->val += ch;
531 511 } else if (ch == '.') {
532 512 this->state = st_decimal;
533   - this->val += ch;
534 513 } else {
535 514 this->state = st_literal;
536 515 inLiteral(ch);
... ... @@ -542,7 +521,6 @@ QPDFTokenizer::inDecimal(char ch)
542 521 {
543 522 if (QUtil::is_digit(ch)) {
544 523 this->state = st_real;
545   - this->val += ch;
546 524 } else {
547 525 this->state = st_literal;
548 526 inLiteral(ch);
... ... @@ -553,10 +531,8 @@ void
553 531 QPDFTokenizer::inNumber(char ch)
554 532 {
555 533 if (QUtil::is_digit(ch)) {
556   - this->val += ch;
557 534 } else if (ch == '.') {
558 535 this->state = st_real;
559   - this->val += ch;
560 536 } else if (isDelimiter(ch)) {
561 537 this->type = tt_integer;
562 538 this->state = st_token_ready;
... ... @@ -564,7 +540,6 @@ QPDFTokenizer::inNumber(char ch)
564 540 this->char_to_unread = ch;
565 541 } else {
566 542 this->state = st_literal;
567   - this->val += ch;
568 543 }
569 544 }
570 545  
... ... @@ -572,7 +547,6 @@ void
572 547 QPDFTokenizer::inReal(char ch)
573 548 {
574 549 if (QUtil::is_digit(ch)) {
575   - this->val += ch;
576 550 } else if (isDelimiter(ch)) {
577 551 this->type = tt_real;
578 552 this->state = st_token_ready;
... ... @@ -580,7 +554,6 @@ QPDFTokenizer::inReal(char ch)
580 554 this->char_to_unread = ch;
581 555 } else {
582 556 this->state = st_literal;
583   - this->val += ch;
584 557 }
585 558 }
586 559 void
... ... @@ -649,7 +622,6 @@ void
649 622 QPDFTokenizer::inLt(char ch)
650 623 {
651 624 if (ch == '<') {
652   - this->val += "<<";
653 625 this->type = tt_dict_open;
654 626 this->state = st_token_ready;
655 627 return;
... ... @@ -663,11 +635,9 @@ void
663 635 QPDFTokenizer::inGt(char ch)
664 636 {
665 637 if (ch == '>') {
666   - this->val += ">>";
667 638 this->type = tt_dict_close;
668 639 this->state = st_token_ready;
669 640 } else {
670   - this->val += ">";
671 641 this->type = tt_bad;
672 642 QTC::TC("qpdf", "QPDFTokenizer bad >");
673 643 this->error_message = "unexpected >";
... ... @@ -692,11 +662,9 @@ QPDFTokenizer::inLiteral(char ch)
692 662 this->in_token = false;
693 663 this->char_to_unread = ch;
694 664 this->state = st_token_ready;
695   - this->type = (this->val == "true") || (this->val == "false")
  665 + this->type = (this->raw_val == "true") || (this->raw_val == "false")
696 666 ? tt_bool
697   - : (this->val == "null" ? tt_null : tt_word);
698   - } else {
699   - this->val += ch;
  667 + : (this->raw_val == "null" ? tt_null : tt_word);
700 668 }
701 669 }
702 670  
... ... @@ -783,8 +751,7 @@ QPDFTokenizer::inCharCode(char ch)
783 751 void
784 752 QPDFTokenizer::inInlineImage(char ch)
785 753 {
786   - this->val += ch;
787   - if (this->val.length() == this->inline_image_bytes) {
  754 + if ((this->raw_val.length() + 1) == this->inline_image_bytes) {
788 755 QTC::TC("qpdf", "QPDFTokenizer found EI by byte count");
789 756 this->type = tt_inline_image;
790 757 this->inline_image_bytes = 0;
... ... @@ -951,7 +918,7 @@ QPDFTokenizer::getToken(Token&amp; token, bool&amp; unread_char, char&amp; ch)
951 918 unread_char = !this->in_token && !this->before_token;
952 919 ch = this->char_to_unread;
953 920 if (ready) {
954   - token = (this->type == tt_bad)
  921 + token = (!(this->type == tt_name || this->type == tt_string))
955 922 ? Token(
956 923 this->type, this->raw_val, this->raw_val, this->error_message)
957 924 : Token(this->type, this->val, this->raw_val, this->error_message);
... ...