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/runtime.cc

Issue 2858033: Fix Chromium issue 47824. (Closed)
Patch Set: Addressed review comments Created 10 years, 5 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 | « src/regexp-macro-assembler.cc ('k') | test/cctest/test-api.cc » ('j') | 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 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 2775
2776 if (!sub->IsFlat()) { 2776 if (!sub->IsFlat()) {
2777 FlattenString(sub); 2777 FlattenString(sub);
2778 } 2778 }
2779 2779
2780 // Searching for one specific character is common. For one 2780 // Searching for one specific character is common. For one
2781 // character patterns linear search is necessary, so any smart 2781 // character patterns linear search is necessary, so any smart
2782 // algorithm is unnecessary overhead. 2782 // algorithm is unnecessary overhead.
2783 if (pattern_length == 1) { 2783 if (pattern_length == 1) {
2784 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 2784 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
2785 if (sub->IsAsciiRepresentation()) { 2785 String* seq_sub = *sub;
2786 if (seq_sub->IsConsString()) {
2787 seq_sub = ConsString::cast(seq_sub)->first();
2788 }
2789 if (seq_sub->IsAsciiRepresentation()) {
2786 uc16 pchar = pat->Get(0); 2790 uc16 pchar = pat->Get(0);
2787 if (pchar > String::kMaxAsciiCharCode) { 2791 if (pchar > String::kMaxAsciiCharCode) {
2788 return -1; 2792 return -1;
2789 } 2793 }
2790 Vector<const char> ascii_vector = 2794 Vector<const char> ascii_vector =
2791 sub->ToAsciiVector().SubVector(start_index, subject_length); 2795 seq_sub->ToAsciiVector().SubVector(start_index, subject_length);
2792 const void* pos = memchr(ascii_vector.start(), 2796 const void* pos = memchr(ascii_vector.start(),
2793 static_cast<const char>(pchar), 2797 static_cast<const char>(pchar),
2794 static_cast<size_t>(ascii_vector.length())); 2798 static_cast<size_t>(ascii_vector.length()));
2795 if (pos == NULL) { 2799 if (pos == NULL) {
2796 return -1; 2800 return -1;
2797 } 2801 }
2798 return static_cast<int>(reinterpret_cast<const char*>(pos) 2802 return static_cast<int>(reinterpret_cast<const char*>(pos)
2799 - ascii_vector.start() + start_index); 2803 - ascii_vector.start() + start_index);
2800 } 2804 }
2801 return SingleCharIndexOf(sub->ToUC16Vector(), pat->Get(0), start_index); 2805 return SingleCharIndexOf(seq_sub->ToUC16Vector(),
2806 pat->Get(0),
2807 start_index);
2802 } 2808 }
2803 2809
2804 if (!pat->IsFlat()) { 2810 if (!pat->IsFlat()) {
2805 FlattenString(pat); 2811 FlattenString(pat);
2806 } 2812 }
2807 2813
2808 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 2814 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
2815 // Extract flattened substrings of cons strings before determining asciiness.
2816 String* seq_sub = *sub;
2817 if (seq_sub->IsConsString()) {
2818 seq_sub = ConsString::cast(seq_sub)->first();
2819 }
2820 String* seq_pat = *pat;
2821 if (seq_pat->IsConsString()) {
2822 seq_pat = ConsString::cast(seq_pat)->first();
2823 }
2824
2809 // dispatch on type of strings 2825 // dispatch on type of strings
2810 if (pat->IsAsciiRepresentation()) { 2826 if (seq_pat->IsAsciiRepresentation()) {
2811 Vector<const char> pat_vector = pat->ToAsciiVector(); 2827 Vector<const char> pat_vector = seq_pat->ToAsciiVector();
2812 if (sub->IsAsciiRepresentation()) { 2828 if (seq_sub->IsAsciiRepresentation()) {
2813 return StringSearch(sub->ToAsciiVector(), pat_vector, start_index); 2829 return StringSearch(seq_sub->ToAsciiVector(), pat_vector, start_index);
2814 } 2830 }
2815 return StringSearch(sub->ToUC16Vector(), pat_vector, start_index); 2831 return StringSearch(seq_sub->ToUC16Vector(), pat_vector, start_index);
2816 } 2832 }
2817 Vector<const uc16> pat_vector = pat->ToUC16Vector(); 2833 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector();
2818 if (sub->IsAsciiRepresentation()) { 2834 if (seq_sub->IsAsciiRepresentation()) {
2819 return StringSearch(sub->ToAsciiVector(), pat_vector, start_index); 2835 return StringSearch(seq_sub->ToAsciiVector(), pat_vector, start_index);
2820 } 2836 }
2821 return StringSearch(sub->ToUC16Vector(), pat_vector, start_index); 2837 return StringSearch(seq_sub->ToUC16Vector(), pat_vector, start_index);
2822 } 2838 }
2823 2839
2824 2840
2825 static Object* Runtime_StringIndexOf(Arguments args) { 2841 static Object* Runtime_StringIndexOf(Arguments args) {
2826 HandleScope scope; // create a new handle scope 2842 HandleScope scope; // create a new handle scope
2827 ASSERT(args.length() == 3); 2843 ASSERT(args.length() == 3);
2828 2844
2829 CONVERT_ARG_CHECKED(String, sub, 0); 2845 CONVERT_ARG_CHECKED(String, sub, 0);
2830 CONVERT_ARG_CHECKED(String, pat, 1); 2846 CONVERT_ARG_CHECKED(String, pat, 1);
2831 2847
(...skipping 7547 matching lines...) Expand 10 before | Expand all | Expand 10 after
10379 } else { 10395 } else {
10380 // Handle last resort GC and make sure to allow future allocations 10396 // Handle last resort GC and make sure to allow future allocations
10381 // to grow the heap without causing GCs (if possible). 10397 // to grow the heap without causing GCs (if possible).
10382 Counters::gc_last_resort_from_js.Increment(); 10398 Counters::gc_last_resort_from_js.Increment();
10383 Heap::CollectAllGarbage(false); 10399 Heap::CollectAllGarbage(false);
10384 } 10400 }
10385 } 10401 }
10386 10402
10387 10403
10388 } } // namespace v8::internal 10404 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698