Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/regexp/jsregexp.cc

Issue 1825053002: Version 5.0.71.24 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@5.0
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/ast/ast.h" 7 #include "src/ast/ast.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/compilation-cache.h" 9 #include "src/compilation-cache.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 } 1967 }
1968 } 1968 }
1969 1969
1970 1970
1971 // Gets a series of segment boundaries representing a character class. If the 1971 // Gets a series of segment boundaries representing a character class. If the
1972 // character is in the range between an even and an odd boundary (counting from 1972 // character is in the range between an even and an odd boundary (counting from
1973 // start_index) then go to even_label, otherwise go to odd_label. We already 1973 // start_index) then go to even_label, otherwise go to odd_label. We already
1974 // know that the character is in the range of min_char to max_char inclusive. 1974 // know that the character is in the range of min_char to max_char inclusive.
1975 // Either label can be NULL indicating backtracking. Either label can also be 1975 // Either label can be NULL indicating backtracking. Either label can also be
1976 // equal to the fall_through label. 1976 // equal to the fall_through label.
1977 static void GenerateBranches(RegExpMacroAssembler* masm, 1977 static void GenerateBranches(RegExpMacroAssembler* masm, ZoneList<int>* ranges,
1978 ZoneList<int>* ranges, 1978 int start_index, int end_index, uc32 min_char,
1979 int start_index, 1979 uc32 max_char, Label* fall_through,
1980 int end_index, 1980 Label* even_label, Label* odd_label) {
1981 uc16 min_char, 1981 DCHECK_LE(min_char, String::kMaxUtf16CodeUnit);
1982 uc16 max_char, 1982 DCHECK_LE(max_char, String::kMaxUtf16CodeUnit);
1983 Label* fall_through, 1983
1984 Label* even_label,
1985 Label* odd_label) {
1986 int first = ranges->at(start_index); 1984 int first = ranges->at(start_index);
1987 int last = ranges->at(end_index) - 1; 1985 int last = ranges->at(end_index) - 1;
1988 1986
1989 DCHECK_LT(min_char, first); 1987 DCHECK_LT(min_char, first);
1990 1988
1991 // Just need to test if the character is before or on-or-after 1989 // Just need to test if the character is before or on-or-after
1992 // a particular character. 1990 // a particular character.
1993 if (start_index == end_index) { 1991 if (start_index == end_index) {
1994 EmitBoundaryTest(masm, first, fall_through, even_label, odd_label); 1992 EmitBoundaryTest(masm, first, fall_through, even_label, odd_label);
1995 return; 1993 return;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 if (compiler->one_byte()) { 2483 if (compiler->one_byte()) {
2486 char_mask = String::kMaxOneByteCharCode; 2484 char_mask = String::kMaxOneByteCharCode;
2487 } else { 2485 } else {
2488 char_mask = String::kMaxUtf16CodeUnit; 2486 char_mask = String::kMaxUtf16CodeUnit;
2489 } 2487 }
2490 if ((mask & char_mask) == char_mask) need_mask = false; 2488 if ((mask & char_mask) == char_mask) need_mask = false;
2491 mask &= char_mask; 2489 mask &= char_mask;
2492 } else { 2490 } else {
2493 // For 2-character preloads in one-byte mode or 1-character preloads in 2491 // For 2-character preloads in one-byte mode or 1-character preloads in
2494 // two-byte mode we also use a 16 bit load with zero extend. 2492 // two-byte mode we also use a 16 bit load with zero extend.
2493 static const uint32_t kTwoByteMask = 0xffff;
2494 static const uint32_t kFourByteMask = 0xffffffff;
2495 if (details->characters() == 2 && compiler->one_byte()) { 2495 if (details->characters() == 2 && compiler->one_byte()) {
2496 if ((mask & 0xffff) == 0xffff) need_mask = false; 2496 if ((mask & kTwoByteMask) == kTwoByteMask) need_mask = false;
2497 } else if (details->characters() == 1 && !compiler->one_byte()) { 2497 } else if (details->characters() == 1 && !compiler->one_byte()) {
2498 if ((mask & 0xffff) == 0xffff) need_mask = false; 2498 if ((mask & kTwoByteMask) == kTwoByteMask) need_mask = false;
2499 } else { 2499 } else {
2500 if (mask == 0xffffffff) need_mask = false; 2500 if (mask == kFourByteMask) need_mask = false;
2501 } 2501 }
2502 } 2502 }
2503 2503
2504 if (fall_through_on_failure) { 2504 if (fall_through_on_failure) {
2505 if (need_mask) { 2505 if (need_mask) {
2506 assembler->CheckCharacterAfterAnd(value, mask, on_possible_success); 2506 assembler->CheckCharacterAfterAnd(value, mask, on_possible_success);
2507 } else { 2507 } else {
2508 assembler->CheckCharacter(value, on_possible_success); 2508 assembler->CheckCharacter(value, on_possible_success);
2509 } 2509 }
2510 } else { 2510 } else {
(...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after
4803 } 4803 }
4804 for (int i = 0; i < length; i += 2) { 4804 for (int i = 0; i < length; i += 2) {
4805 if (special_class[i] != (range.to() + 1)) { 4805 if (special_class[i] != (range.to() + 1)) {
4806 return false; 4806 return false;
4807 } 4807 }
4808 range = ranges->at((i >> 1) + 1); 4808 range = ranges->at((i >> 1) + 1);
4809 if (special_class[i+1] != range.from()) { 4809 if (special_class[i+1] != range.from()) {
4810 return false; 4810 return false;
4811 } 4811 }
4812 } 4812 }
4813 if (range.to() != 0xffff) { 4813 if (range.to() != String::kMaxCodePoint) {
4814 return false; 4814 return false;
4815 } 4815 }
4816 return true; 4816 return true;
4817 } 4817 }
4818 4818
4819 4819
4820 static bool CompareRanges(ZoneList<CharacterRange>* ranges, 4820 static bool CompareRanges(ZoneList<CharacterRange>* ranges,
4821 const int* special_class, 4821 const int* special_class,
4822 int length) { 4822 int length) {
4823 length--; // Remove final marker. 4823 length--; // Remove final marker.
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
5874 } 5874 }
5875 5875
5876 5876
5877 void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone, 5877 void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone,
5878 ZoneList<CharacterRange>* ranges, 5878 ZoneList<CharacterRange>* ranges,
5879 bool is_one_byte) { 5879 bool is_one_byte) {
5880 int range_count = ranges->length(); 5880 int range_count = ranges->length();
5881 for (int i = 0; i < range_count; i++) { 5881 for (int i = 0; i < range_count; i++) {
5882 CharacterRange range = ranges->at(i); 5882 CharacterRange range = ranges->at(i);
5883 uc32 bottom = range.from(); 5883 uc32 bottom = range.from();
5884 uc32 top = range.to(); 5884 if (bottom > String::kMaxUtf16CodeUnit) return;
5885 uc32 top = Min(range.to(), String::kMaxUtf16CodeUnit);
5885 // Nothing to be done for surrogates. 5886 // Nothing to be done for surrogates.
5886 if (bottom >= kLeadSurrogateStart && top <= kTrailSurrogateEnd) return; 5887 if (bottom >= kLeadSurrogateStart && top <= kTrailSurrogateEnd) return;
5887 if (is_one_byte && !RangeContainsLatin1Equivalents(range)) { 5888 if (is_one_byte && !RangeContainsLatin1Equivalents(range)) {
5888 if (bottom > String::kMaxOneByteCharCode) return; 5889 if (bottom > String::kMaxOneByteCharCode) return;
5889 if (top > String::kMaxOneByteCharCode) top = String::kMaxOneByteCharCode; 5890 if (top > String::kMaxOneByteCharCode) top = String::kMaxOneByteCharCode;
5890 } 5891 }
5891 unibrow::uchar chars[unibrow::Ecma262UnCanonicalize::kMaxWidth]; 5892 unibrow::uchar chars[unibrow::Ecma262UnCanonicalize::kMaxWidth];
5892 if (top == bottom) { 5893 if (top == bottom) {
5893 // If this is a singleton we just expand the one character. 5894 // If this is a singleton we just expand the one character.
5894 int length = isolate->jsregexp_uncanonicalize()->get(bottom, '\0', chars); 5895 int length = isolate->jsregexp_uncanonicalize()->get(bottom, '\0', chars);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
6236 ins.set_value(Entry(current.to() + 1, 6237 ins.set_value(Entry(current.to() + 1,
6237 entry->to(), 6238 entry->to(),
6238 entry->out_set())); 6239 entry->out_set()));
6239 entry->set_to(current.to()); 6240 entry->set_to(current.to());
6240 } 6241 }
6241 DCHECK(entry->to() <= current.to()); 6242 DCHECK(entry->to() <= current.to());
6242 // The overlapping range is now completely contained by the range 6243 // The overlapping range is now completely contained by the range
6243 // we're adding so we can just update it and move the start point 6244 // we're adding so we can just update it and move the start point
6244 // of the range we're adding just past it. 6245 // of the range we're adding just past it.
6245 entry->AddValue(value, zone); 6246 entry->AddValue(value, zone);
6246 // Bail out if the last interval ended at 0xFFFF since otherwise
6247 // adding 1 will wrap around to 0.
6248 if (entry->to() == String::kMaxUtf16CodeUnit)
6249 break;
6250 DCHECK(entry->to() + 1 > current.from()); 6247 DCHECK(entry->to() + 1 > current.from());
6251 current.set_from(entry->to() + 1); 6248 current.set_from(entry->to() + 1);
6252 } else { 6249 } else {
6253 // There is no overlap so we can just add the range 6250 // There is no overlap so we can just add the range
6254 ZoneSplayTree<Config>::Locator ins; 6251 ZoneSplayTree<Config>::Locator ins;
6255 bool inserted = tree()->Insert(current.from(), &ins); 6252 bool inserted = tree()->Insert(current.from(), &ins);
6256 DCHECK(inserted); 6253 DCHECK(inserted);
6257 USE(inserted); 6254 USE(inserted);
6258 ins.set_value(Entry(current.from(), 6255 ins.set_value(Entry(current.from(),
6259 current.to(), 6256 current.to(),
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
6530 6527
6531 6528
6532 void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) { 6529 void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) {
6533 ranges->Sort(CompareRangeByFrom); 6530 ranges->Sort(CompareRangeByFrom);
6534 uc16 last = 0; 6531 uc16 last = 0;
6535 for (int i = 0; i < ranges->length(); i++) { 6532 for (int i = 0; i < ranges->length(); i++) {
6536 CharacterRange range = ranges->at(i); 6533 CharacterRange range = ranges->at(i);
6537 if (last < range.from()) 6534 if (last < range.from())
6538 AddRange(CharacterRange::Range(last, range.from() - 1)); 6535 AddRange(CharacterRange::Range(last, range.from() - 1));
6539 if (range.to() >= last) { 6536 if (range.to() >= last) {
6540 if (range.to() == String::kMaxUtf16CodeUnit) { 6537 if (range.to() == String::kMaxCodePoint) {
6541 return; 6538 return;
6542 } else { 6539 } else {
6543 last = range.to() + 1; 6540 last = range.to() + 1;
6544 } 6541 }
6545 } 6542 }
6546 } 6543 }
6547 AddRange(CharacterRange::Range(last, String::kMaxUtf16CodeUnit)); 6544 AddRange(CharacterRange::Range(last, String::kMaxCodePoint));
6548 } 6545 }
6549 6546
6550 6547
6551 void DispatchTableConstructor::VisitText(TextNode* that) { 6548 void DispatchTableConstructor::VisitText(TextNode* that) {
6552 TextElement elm = that->elements()->at(0); 6549 TextElement elm = that->elements()->at(0);
6553 switch (elm.text_type()) { 6550 switch (elm.text_type()) {
6554 case TextElement::ATOM: { 6551 case TextElement::ATOM: {
6555 uc16 c = elm.atom()->data()[0]; 6552 uc16 c = elm.atom()->data()[0];
6556 AddRange(CharacterRange::Range(c, c)); 6553 AddRange(CharacterRange::Range(c, c));
6557 break; 6554 break;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
6862 6859
6863 6860
6864 void RegExpResultsCache::Clear(FixedArray* cache) { 6861 void RegExpResultsCache::Clear(FixedArray* cache) {
6865 for (int i = 0; i < kRegExpResultsCacheSize; i++) { 6862 for (int i = 0; i < kRegExpResultsCacheSize; i++) {
6866 cache->set(i, Smi::FromInt(0)); 6863 cache->set(i, Smi::FromInt(0));
6867 } 6864 }
6868 } 6865 }
6869 6866
6870 } // namespace internal 6867 } // namespace internal
6871 } // namespace v8 6868 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698