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