Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 LAST(ADD_CHAR); | 380 LAST(ADD_CHAR); |
| 381 } | 381 } |
| 382 | 382 |
| 383 | 383 |
| 384 void RegExpBuilder::AddEmpty() { | 384 void RegExpBuilder::AddEmpty() { |
| 385 pending_empty_ = true; | 385 pending_empty_ = true; |
| 386 } | 386 } |
| 387 | 387 |
| 388 | 388 |
| 389 void RegExpBuilder::AddAtom(RegExpTree* term) { | 389 void RegExpBuilder::AddAtom(RegExpTree* term) { |
| 390 if (term->IsEmpty()) { | |
| 391 AddEmpty(); | |
| 392 return; | |
| 393 } | |
| 390 if (term->IsTextElement()) { | 394 if (term->IsTextElement()) { |
| 391 FlushCharacters(); | 395 FlushCharacters(); |
| 392 text_.Add(term); | 396 text_.Add(term); |
| 393 } else { | 397 } else { |
| 394 FlushText(); | 398 FlushText(); |
| 395 terms_.Add(term); | 399 terms_.Add(term); |
| 396 } | 400 } |
| 397 LAST(ADD_ATOM); | 401 LAST(ADD_ATOM); |
| 398 } | 402 } |
| 399 | 403 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 characters_ = NULL; | 467 characters_ = NULL; |
| 464 atom = new RegExpAtom(char_vector); | 468 atom = new RegExpAtom(char_vector); |
| 465 FlushText(); | 469 FlushText(); |
| 466 } else if (text_.length() > 0) { | 470 } else if (text_.length() > 0) { |
| 467 ASSERT(last_added_ == ADD_ATOM); | 471 ASSERT(last_added_ == ADD_ATOM); |
| 468 atom = text_.RemoveLast(); | 472 atom = text_.RemoveLast(); |
| 469 FlushText(); | 473 FlushText(); |
| 470 } else if (terms_.length() > 0) { | 474 } else if (terms_.length() > 0) { |
| 471 ASSERT(last_added_ == ADD_ATOM); | 475 ASSERT(last_added_ == ADD_ATOM); |
| 472 atom = terms_.RemoveLast(); | 476 atom = terms_.RemoveLast(); |
| 477 if (atom->IsLookahead() || atom->IsAssertion()) { | |
|
Christian Plesner Hansen
2008/11/17 10:54:35
I wonder if this is worthwhile?
Lasse Reichstein
2008/11/17 11:26:32
It probably isn't. It's optimizing the case where
| |
| 478 // Guaranteed not to match a non-empty string. | |
| 479 // Assertion as an atom can happen as, e.g., (?:\b) | |
| 480 LAST(ADD_TERM); | |
| 481 if (min == 0) { | |
| 482 return; | |
| 483 } | |
| 484 terms_.Add(atom); | |
| 485 return; | |
| 486 } | |
| 473 } else { | 487 } else { |
| 474 // Only call immediately after adding an atom or character! | 488 // Only call immediately after adding an atom or character! |
| 475 UNREACHABLE(); | 489 UNREACHABLE(); |
| 476 return; | 490 return; |
| 477 } | 491 } |
| 478 terms_.Add(new RegExpQuantifier(min, max, is_greedy, atom)); | 492 terms_.Add(new RegExpQuantifier(min, max, is_greedy, atom)); |
| 479 LAST(ADD_TERM); | 493 LAST(ADD_TERM); |
| 480 } | 494 } |
| 481 | 495 |
| 482 | 496 |
| (...skipping 3836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4319 start_position, | 4333 start_position, |
| 4320 is_expression); | 4334 is_expression); |
| 4321 return result; | 4335 return result; |
| 4322 } | 4336 } |
| 4323 | 4337 |
| 4324 | 4338 |
| 4325 #undef NEW | 4339 #undef NEW |
| 4326 | 4340 |
| 4327 | 4341 |
| 4328 } } // namespace v8::internal | 4342 } } // namespace v8::internal |
| OLD | NEW |