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

Side by Side Diff: src/runtime.cc

Issue 11299163: Optimize non-ASCII string splitting with single-character search pattern (Closed)
Patch Set: Created 8 years, 1 month 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 pos = reinterpret_cast<const char*>( 2755 pos = reinterpret_cast<const char*>(
2756 memchr(pos, pattern, subject_end - pos)); 2756 memchr(pos, pattern, subject_end - pos));
2757 if (pos == NULL) return; 2757 if (pos == NULL) return;
2758 indices->Add(static_cast<int>(pos - subject_start), zone); 2758 indices->Add(static_cast<int>(pos - subject_start), zone);
2759 pos++; 2759 pos++;
2760 limit--; 2760 limit--;
2761 } 2761 }
2762 } 2762 }
2763 2763
2764 2764
2765 void FindTwoByteStringIndices(const Vector<const uc16> subject,
2766 uc16 pattern,
2767 ZoneList<int>* indices,
2768 unsigned int limit,
2769 Zone* zone) {
2770 ASSERT(limit > 0);
2771 const uc16* subject_start = subject.start();
2772 const uc16* subject_end = subject_start + subject.length();
2773 for (const uc16* pos = subject_start; pos < subject_end && limit > 0; pos++) {
2774 if (*pos == pattern) {
2775 indices->Add(static_cast<int>(pos - subject_start), zone);
2776 limit--;
2777 }
2778 }
2779 }
2780
2781
2765 template <typename SubjectChar, typename PatternChar> 2782 template <typename SubjectChar, typename PatternChar>
2766 void FindStringIndices(Isolate* isolate, 2783 void FindStringIndices(Isolate* isolate,
2767 Vector<const SubjectChar> subject, 2784 Vector<const SubjectChar> subject,
2768 Vector<const PatternChar> pattern, 2785 Vector<const PatternChar> pattern,
2769 ZoneList<int>* indices, 2786 ZoneList<int>* indices,
2770 unsigned int limit, 2787 unsigned int limit,
2771 Zone* zone) { 2788 Zone* zone) {
2772 ASSERT(limit > 0); 2789 ASSERT(limit > 0);
2773 // Collect indices of pattern in subject. 2790 // Collect indices of pattern in subject.
2774 // Stop after finding at most limit values. 2791 // Stop after finding at most limit values.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2818 } else { 2835 } else {
2819 FindStringIndices(isolate, 2836 FindStringIndices(isolate,
2820 subject_vector, 2837 subject_vector,
2821 pattern_content.ToUC16Vector(), 2838 pattern_content.ToUC16Vector(),
2822 indices, 2839 indices,
2823 limit, 2840 limit,
2824 zone); 2841 zone);
2825 } 2842 }
2826 } else { 2843 } else {
2827 Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); 2844 Vector<const uc16> subject_vector = subject_content.ToUC16Vector();
2828 if (pattern_content.IsAscii()) { 2845 if (pattern_content.Length() == 1) {
2829 FindStringIndices(isolate, 2846 uc16 pattern_char = pattern_content.IsAscii() ?
2830 subject_vector, 2847 pattern_content.ToAsciiVector()[0] :
2831 pattern_content.ToAsciiVector(), 2848 pattern_content.ToUC16Vector()[0];
2832 indices, 2849 FindTwoByteStringIndices(subject_vector,
2833 limit, 2850 pattern_char,
2834 zone); 2851 indices,
2852 limit,
2853 zone);
2854 } else if (pattern_content.IsAscii()) {
2855 FindStringIndices(isolate,
2856 subject_vector,
2857 pattern_content.ToAsciiVector(),
2858 indices,
2859 limit,
2860 zone);
Yang 2012/11/26 08:45:30 Since we are doing the IsAscii() check (implied in
2835 } else { 2861 } else {
2836 FindStringIndices(isolate, 2862 FindStringIndices(isolate,
2837 subject_vector, 2863 subject_vector,
2838 pattern_content.ToUC16Vector(), 2864 pattern_content.ToUC16Vector(),
2839 indices, 2865 indices,
2840 limit, 2866 limit,
2841 zone); 2867 zone);
2842 } 2868 }
2843 } 2869 }
2844 } 2870 }
(...skipping 10537 matching lines...) Expand 10 before | Expand all | Expand 10 after
13382 // Handle last resort GC and make sure to allow future allocations 13408 // Handle last resort GC and make sure to allow future allocations
13383 // to grow the heap without causing GCs (if possible). 13409 // to grow the heap without causing GCs (if possible).
13384 isolate->counters()->gc_last_resort_from_js()->Increment(); 13410 isolate->counters()->gc_last_resort_from_js()->Increment();
13385 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13411 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13386 "Runtime::PerformGC"); 13412 "Runtime::PerformGC");
13387 } 13413 }
13388 } 13414 }
13389 13415
13390 13416
13391 } } // namespace v8::internal 13417 } } // namespace v8::internal
OLDNEW
« src/objects.h ('K') | « src/objects.h ('k') | test/mjsunit/string-split.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698