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

Side by Side Diff: src/runtime.cc

Issue 5270006: Maintain the invariant that the pattern string in an atom regexp is always ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « src/jsregexp.cc ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 2012
2013 2013
2014 void IncrementCharacterCount(int by) { 2014 void IncrementCharacterCount(int by) {
2015 if (character_count_ > String::kMaxLength - by) { 2015 if (character_count_ > String::kMaxLength - by) {
2016 V8::FatalProcessOutOfMemory("String.replace result too large."); 2016 V8::FatalProcessOutOfMemory("String.replace result too large.");
2017 } 2017 }
2018 character_count_ += by; 2018 character_count_ += by;
2019 } 2019 }
2020 2020
2021 Handle<JSArray> GetParts() { 2021 Handle<JSArray> GetParts() {
2022 Handle<JSArray> result = 2022 return array_builder_.ToJSArray();
2023 Factory::NewJSArrayWithElements(array_builder_.array());
2024 result->set_length(Smi::FromInt(array_builder_.length()));
2025 return result;
2026 } 2023 }
2027 2024
2028 private: 2025 private:
2029 Handle<String> NewRawAsciiString(int size) { 2026 Handle<String> NewRawAsciiString(int size) {
2030 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(size), String); 2027 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(size), String);
2031 } 2028 }
2032 2029
2033 2030
2034 Handle<String> NewRawTwoByteString(int size) { 2031 Handle<String> NewRawTwoByteString(int size) {
2035 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(size), String); 2032 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(size), String);
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 2587
2591 return StringReplaceRegExpWithString(subject, 2588 return StringReplaceRegExpWithString(subject,
2592 regexp, 2589 regexp,
2593 replacement, 2590 replacement,
2594 last_match_info); 2591 last_match_info);
2595 } 2592 }
2596 2593
2597 2594
2598 // Perform string match of pattern on subject, starting at start index. 2595 // Perform string match of pattern on subject, starting at start index.
2599 // Caller must ensure that 0 <= start_index <= sub->length(), 2596 // Caller must ensure that 0 <= start_index <= sub->length(),
2600 // and should check that pat->length() + start_index <= sub->length() 2597 // and should check that pat->length() + start_index <= sub->length().
2601 int Runtime::StringMatch(Handle<String> sub, 2598 int Runtime::StringMatch(Handle<String> sub,
2602 Handle<String> pat, 2599 Handle<String> pat,
2603 int start_index) { 2600 int start_index) {
2604 ASSERT(0 <= start_index); 2601 ASSERT(0 <= start_index);
2605 ASSERT(start_index <= sub->length()); 2602 ASSERT(start_index <= sub->length());
2606 2603
2607 int pattern_length = pat->length(); 2604 int pattern_length = pat->length();
2608 if (pattern_length == 0) return start_index; 2605 if (pattern_length == 0) return start_index;
2609 2606
2610 int subject_length = sub->length(); 2607 int subject_length = sub->length();
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
3189 result_elements = 3186 result_elements =
3190 Handle<FixedArray>(FixedArray::cast(result_array->elements())); 3187 Handle<FixedArray>(FixedArray::cast(result_array->elements()));
3191 } else { 3188 } else {
3192 result_elements = Factory::NewFixedArrayWithHoles(16); 3189 result_elements = Factory::NewFixedArrayWithHoles(16);
3193 } 3190 }
3194 FixedArrayBuilder builder(result_elements); 3191 FixedArrayBuilder builder(result_elements);
3195 3192
3196 if (regexp->TypeTag() == JSRegExp::ATOM) { 3193 if (regexp->TypeTag() == JSRegExp::ATOM) {
3197 Handle<String> pattern( 3194 Handle<String> pattern(
3198 String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex))); 3195 String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex)));
3199 if (!pattern->IsFlat()) FlattenString(pattern); 3196 ASSERT(pattern->IsFlat());
3200 if (SearchStringMultiple(subject, pattern, last_match_info, &builder)) { 3197 if (SearchStringMultiple(subject, pattern, last_match_info, &builder)) {
3201 return *builder.ToJSArray(result_array); 3198 return *builder.ToJSArray(result_array);
3202 } 3199 }
3203 return Heap::null_value(); 3200 return Heap::null_value();
3204 } 3201 }
3205 3202
3206 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); 3203 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
3207 3204
3208 RegExpImpl::IrregexpResult result; 3205 RegExpImpl::IrregexpResult result;
3209 if (regexp->CaptureCount() == 0) { 3206 if (regexp->CaptureCount() == 0) {
(...skipping 7115 matching lines...) Expand 10 before | Expand all | Expand 10 after
10325 } else { 10322 } else {
10326 // Handle last resort GC and make sure to allow future allocations 10323 // Handle last resort GC and make sure to allow future allocations
10327 // to grow the heap without causing GCs (if possible). 10324 // to grow the heap without causing GCs (if possible).
10328 Counters::gc_last_resort_from_js.Increment(); 10325 Counters::gc_last_resort_from_js.Increment();
10329 Heap::CollectAllGarbage(false); 10326 Heap::CollectAllGarbage(false);
10330 } 10327 }
10331 } 10328 }
10332 10329
10333 10330
10334 } } // namespace v8::internal 10331 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698