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

Side by Side Diff: src/runtime.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implemented suggested changes. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 2950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2961 int pattern_length = pat->length(); 2961 int pattern_length = pat->length();
2962 if (pattern_length == 0) return start_index; 2962 if (pattern_length == 0) return start_index;
2963 2963
2964 int subject_length = sub->length(); 2964 int subject_length = sub->length();
2965 if (start_index + pattern_length > subject_length) return -1; 2965 if (start_index + pattern_length > subject_length) return -1;
2966 2966
2967 if (!sub->IsFlat()) FlattenString(sub); 2967 if (!sub->IsFlat()) FlattenString(sub);
2968 if (!pat->IsFlat()) FlattenString(pat); 2968 if (!pat->IsFlat()) FlattenString(pat);
2969 2969
2970 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 2970 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
2971 // Extract flattened substrings of cons strings before determining asciiness.
2972 String* seq_sub = *sub;
2973 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first();
2974 String* seq_pat = *pat;
2975 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first();
2976 2971
2977 // dispatch on type of strings 2972 // dispatch on type of strings
2978 if (seq_pat->IsAsciiRepresentation()) { 2973 if (pat->IsAsciiRepresentationUnderneath()) {
2979 Vector<const char> pat_vector = seq_pat->ToAsciiVector(); 2974 Vector<const char> pat_vector = pat->ToAsciiVector();
2980 if (seq_sub->IsAsciiRepresentation()) { 2975 if (sub->IsAsciiRepresentationUnderneath()) {
2981 return SearchString(isolate, 2976 return SearchString(isolate,
2982 seq_sub->ToAsciiVector(), 2977 sub->ToAsciiVector(),
2983 pat_vector, 2978 pat_vector,
2984 start_index); 2979 start_index);
2985 } 2980 }
2986 return SearchString(isolate, 2981 return SearchString(isolate,
2987 seq_sub->ToUC16Vector(), 2982 sub->ToUC16Vector(),
2988 pat_vector, 2983 pat_vector,
2989 start_index); 2984 start_index);
2990 } 2985 }
2991 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector(); 2986 Vector<const uc16> pat_vector = pat->ToUC16Vector();
2992 if (seq_sub->IsAsciiRepresentation()) { 2987 if (sub->IsAsciiRepresentationUnderneath()) {
2993 return SearchString(isolate, 2988 return SearchString(isolate,
2994 seq_sub->ToAsciiVector(), 2989 sub->ToAsciiVector(),
2995 pat_vector, 2990 pat_vector,
2996 start_index); 2991 start_index);
2997 } 2992 }
2998 return SearchString(isolate, 2993 return SearchString(isolate,
2999 seq_sub->ToUC16Vector(), 2994 sub->ToUC16Vector(),
3000 pat_vector, 2995 pat_vector,
3001 start_index); 2996 start_index);
3002 } 2997 }
3003 2998
3004 2999
3005 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) { 3000 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) {
3006 HandleScope scope(isolate); // create a new handle scope 3001 HandleScope scope(isolate); // create a new handle scope
3007 ASSERT(args.length() == 3); 3002 ASSERT(args.length() == 3);
3008 3003
3009 CONVERT_ARG_CHECKED(String, sub, 0); 3004 CONVERT_ARG_CHECKED(String, sub, 0);
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3574 // No matches at all, return failure or exception result directly. 3569 // No matches at all, return failure or exception result directly.
3575 return result; 3570 return result;
3576 } 3571 }
3577 3572
3578 3573
3579 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { 3574 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) {
3580 ASSERT(args.length() == 4); 3575 ASSERT(args.length() == 4);
3581 HandleScope handles(isolate); 3576 HandleScope handles(isolate);
3582 3577
3583 CONVERT_ARG_CHECKED(String, subject, 1); 3578 CONVERT_ARG_CHECKED(String, subject, 1);
3584 if (!subject->IsFlat()) { FlattenString(subject); } 3579 if (!subject->IsFlat()) FlattenString(subject);
3585 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); 3580 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
3586 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2); 3581 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2);
3587 CONVERT_ARG_CHECKED(JSArray, result_array, 3); 3582 CONVERT_ARG_CHECKED(JSArray, result_array, 3);
3588 3583
3589 ASSERT(last_match_info->HasFastElements()); 3584 ASSERT(last_match_info->HasFastElements());
3590 ASSERT(regexp->GetFlags().is_global()); 3585 ASSERT(regexp->GetFlags().is_global());
3591 Handle<FixedArray> result_elements; 3586 Handle<FixedArray> result_elements;
3592 if (result_array->HasFastElements()) { 3587 if (result_array->HasFastElements()) {
3593 result_elements = 3588 result_elements =
3594 Handle<FixedArray>(FixedArray::cast(result_array->elements())); 3589 Handle<FixedArray>(FixedArray::cast(result_array->elements()));
(...skipping 9156 matching lines...) Expand 10 before | Expand all | Expand 10 after
12751 } else { 12746 } else {
12752 // Handle last resort GC and make sure to allow future allocations 12747 // Handle last resort GC and make sure to allow future allocations
12753 // to grow the heap without causing GCs (if possible). 12748 // to grow the heap without causing GCs (if possible).
12754 isolate->counters()->gc_last_resort_from_js()->Increment(); 12749 isolate->counters()->gc_last_resort_from_js()->Increment();
12755 isolate->heap()->CollectAllGarbage(false); 12750 isolate->heap()->CollectAllGarbage(false);
12756 } 12751 }
12757 } 12752 }
12758 12753
12759 12754
12760 } } // namespace v8::internal 12755 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698