OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/jsregexp.h" | 5 #include "src/regexp/jsregexp.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 5334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5345 alternatives->Rewind(write_posn); // Trim end of array. | 5345 alternatives->Rewind(write_posn); // Trim end of array. |
5346 } | 5346 } |
5347 | 5347 |
5348 | 5348 |
5349 // Optimizes b|c|z to [bcz]. | 5349 // Optimizes b|c|z to [bcz]. |
5350 void RegExpDisjunction::FixSingleCharacterDisjunctions( | 5350 void RegExpDisjunction::FixSingleCharacterDisjunctions( |
5351 RegExpCompiler* compiler) { | 5351 RegExpCompiler* compiler) { |
5352 Zone* zone = compiler->zone(); | 5352 Zone* zone = compiler->zone(); |
5353 ZoneList<RegExpTree*>* alternatives = this->alternatives(); | 5353 ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
5354 int length = alternatives->length(); | 5354 int length = alternatives->length(); |
| 5355 const bool unicode = compiler->unicode(); |
5355 | 5356 |
5356 int write_posn = 0; | 5357 int write_posn = 0; |
5357 int i = 0; | 5358 int i = 0; |
5358 while (i < length) { | 5359 while (i < length) { |
5359 RegExpTree* alternative = alternatives->at(i); | 5360 RegExpTree* alternative = alternatives->at(i); |
5360 if (!alternative->IsAtom()) { | 5361 if (!alternative->IsAtom()) { |
5361 alternatives->at(write_posn++) = alternatives->at(i); | 5362 alternatives->at(write_posn++) = alternatives->at(i); |
5362 i++; | 5363 i++; |
5363 continue; | 5364 continue; |
5364 } | 5365 } |
5365 RegExpAtom* atom = alternative->AsAtom(); | 5366 RegExpAtom* atom = alternative->AsAtom(); |
5366 if (atom->length() != 1) { | 5367 if (atom->length() != 1) { |
5367 alternatives->at(write_posn++) = alternatives->at(i); | 5368 alternatives->at(write_posn++) = alternatives->at(i); |
5368 i++; | 5369 i++; |
5369 continue; | 5370 continue; |
5370 } | 5371 } |
5371 DCHECK(!unibrow::Utf16::IsLeadSurrogate(atom->data().at(0))); | 5372 DCHECK_IMPLIES(unicode, |
| 5373 !unibrow::Utf16::IsLeadSurrogate(atom->data().at(0))); |
5372 bool contains_trail_surrogate = | 5374 bool contains_trail_surrogate = |
5373 unibrow::Utf16::IsTrailSurrogate(atom->data().at(0)); | 5375 unibrow::Utf16::IsTrailSurrogate(atom->data().at(0)); |
5374 int first_in_run = i; | 5376 int first_in_run = i; |
5375 i++; | 5377 i++; |
5376 while (i < length) { | 5378 while (i < length) { |
5377 alternative = alternatives->at(i); | 5379 alternative = alternatives->at(i); |
5378 if (!alternative->IsAtom()) break; | 5380 if (!alternative->IsAtom()) break; |
5379 atom = alternative->AsAtom(); | 5381 atom = alternative->AsAtom(); |
5380 if (atom->length() != 1) break; | 5382 if (atom->length() != 1) break; |
5381 DCHECK(!unibrow::Utf16::IsLeadSurrogate(atom->data().at(0))); | 5383 DCHECK_IMPLIES(unicode, |
| 5384 !unibrow::Utf16::IsLeadSurrogate(atom->data().at(0))); |
5382 contains_trail_surrogate |= | 5385 contains_trail_surrogate |= |
5383 unibrow::Utf16::IsTrailSurrogate(atom->data().at(0)); | 5386 unibrow::Utf16::IsTrailSurrogate(atom->data().at(0)); |
5384 i++; | 5387 i++; |
5385 } | 5388 } |
5386 if (i > first_in_run + 1) { | 5389 if (i > first_in_run + 1) { |
5387 // Found non-trivial run of single-character alternatives. | 5390 // Found non-trivial run of single-character alternatives. |
5388 int run_length = i - first_in_run; | 5391 int run_length = i - first_in_run; |
5389 ZoneList<CharacterRange>* ranges = | 5392 ZoneList<CharacterRange>* ranges = |
5390 new (zone) ZoneList<CharacterRange>(2, zone); | 5393 new (zone) ZoneList<CharacterRange>(2, zone); |
5391 for (int j = 0; j < run_length; j++) { | 5394 for (int j = 0; j < run_length; j++) { |
5392 RegExpAtom* old_atom = alternatives->at(j + first_in_run)->AsAtom(); | 5395 RegExpAtom* old_atom = alternatives->at(j + first_in_run)->AsAtom(); |
5393 DCHECK_EQ(old_atom->length(), 1); | 5396 DCHECK_EQ(old_atom->length(), 1); |
5394 ranges->Add(CharacterRange::Singleton(old_atom->data().at(0)), zone); | 5397 ranges->Add(CharacterRange::Singleton(old_atom->data().at(0)), zone); |
5395 } | 5398 } |
5396 RegExpCharacterClass::Flags flags; | 5399 RegExpCharacterClass::Flags flags; |
5397 if (compiler->unicode() && contains_trail_surrogate) { | 5400 if (unicode && contains_trail_surrogate) { |
5398 flags = RegExpCharacterClass::CONTAINS_SPLIT_SURROGATE; | 5401 flags = RegExpCharacterClass::CONTAINS_SPLIT_SURROGATE; |
5399 } | 5402 } |
5400 alternatives->at(write_posn++) = | 5403 alternatives->at(write_posn++) = |
5401 new (zone) RegExpCharacterClass(ranges, flags); | 5404 new (zone) RegExpCharacterClass(ranges, flags); |
5402 } else { | 5405 } else { |
5403 // Just copy any trivial alternatives. | 5406 // Just copy any trivial alternatives. |
5404 for (int j = first_in_run; j < i; j++) { | 5407 for (int j = first_in_run; j < i; j++) { |
5405 alternatives->at(write_posn++) = alternatives->at(j); | 5408 alternatives->at(write_posn++) = alternatives->at(j); |
5406 } | 5409 } |
5407 } | 5410 } |
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6932 | 6935 |
6933 | 6936 |
6934 void RegExpResultsCache::Clear(FixedArray* cache) { | 6937 void RegExpResultsCache::Clear(FixedArray* cache) { |
6935 for (int i = 0; i < kRegExpResultsCacheSize; i++) { | 6938 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
6936 cache->set(i, Smi::kZero); | 6939 cache->set(i, Smi::kZero); |
6937 } | 6940 } |
6938 } | 6941 } |
6939 | 6942 |
6940 } // namespace internal | 6943 } // namespace internal |
6941 } // namespace v8 | 6944 } // namespace v8 |
OLD | NEW |