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

Side by Side Diff: src/runtime/runtime-strings.cc

Issue 2813843002: [string] Add a fast path to String.p.replace (Closed)
Patch Set: Don't scan twice Created 3 years, 8 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/runtime/runtime.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/counters.h" 9 #include "src/counters.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
11 #include "src/regexp/jsregexp-inl.h" 11 #include "src/regexp/jsregexp-inl.h"
12 #include "src/string-builder.h" 12 #include "src/string-builder.h"
13 #include "src/string-search.h" 13 #include "src/string-search.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 17
18 RUNTIME_FUNCTION(Runtime_GetSubstitution) { 18 RUNTIME_FUNCTION(Runtime_GetSubstitution) {
19 HandleScope scope(isolate); 19 HandleScope scope(isolate);
20 DCHECK_EQ(4, args.length()); 20 DCHECK_EQ(5, args.length());
21 CONVERT_ARG_HANDLE_CHECKED(String, matched, 0); 21 CONVERT_ARG_HANDLE_CHECKED(String, matched, 0);
22 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); 22 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
23 CONVERT_SMI_ARG_CHECKED(position, 2); 23 CONVERT_SMI_ARG_CHECKED(position, 2);
24 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 3); 24 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 3);
25 CONVERT_SMI_ARG_CHECKED(start_index, 4);
25 26
26 // A simple match without captures. 27 // A simple match without captures.
27 class SimpleMatch : public String::Match { 28 class SimpleMatch : public String::Match {
28 public: 29 public:
29 SimpleMatch(Handle<String> match, Handle<String> prefix, 30 SimpleMatch(Handle<String> match, Handle<String> prefix,
30 Handle<String> suffix) 31 Handle<String> suffix)
31 : match_(match), prefix_(prefix), suffix_(suffix) {} 32 : match_(match), prefix_(prefix), suffix_(suffix) {}
32 33
33 Handle<String> GetMatch() override { return match_; } 34 Handle<String> GetMatch() override { return match_; }
34 Handle<String> GetPrefix() override { return prefix_; } 35 Handle<String> GetPrefix() override { return prefix_; }
(...skipping 16 matching lines...) Expand all
51 Handle<String> match_, prefix_, suffix_; 52 Handle<String> match_, prefix_, suffix_;
52 }; 53 };
53 54
54 Handle<String> prefix = 55 Handle<String> prefix =
55 isolate->factory()->NewSubString(subject, 0, position); 56 isolate->factory()->NewSubString(subject, 0, position);
56 Handle<String> suffix = isolate->factory()->NewSubString( 57 Handle<String> suffix = isolate->factory()->NewSubString(
57 subject, position + matched->length(), subject->length()); 58 subject, position + matched->length(), subject->length());
58 SimpleMatch match(matched, prefix, suffix); 59 SimpleMatch match(matched, prefix, suffix);
59 60
60 RETURN_RESULT_OR_FAILURE( 61 RETURN_RESULT_OR_FAILURE(
61 isolate, String::GetSubstitution(isolate, &match, replacement)); 62 isolate,
63 String::GetSubstitution(isolate, &match, replacement, start_index));
62 } 64 }
63 65
64 // This may return an empty MaybeHandle if an exception is thrown or 66 // This may return an empty MaybeHandle if an exception is thrown or
65 // we abort due to reaching the recursion limit. 67 // we abort due to reaching the recursion limit.
66 MaybeHandle<String> StringReplaceOneCharWithString( 68 MaybeHandle<String> StringReplaceOneCharWithString(
67 Isolate* isolate, Handle<String> subject, Handle<String> search, 69 Isolate* isolate, Handle<String> subject, Handle<String> search,
68 Handle<String> replace, bool* found, int recursion_limit) { 70 Handle<String> replace, bool* found, int recursion_limit) {
69 StackLimitCheck stackLimitCheck(isolate); 71 StackLimitCheck stackLimitCheck(isolate);
70 if (stackLimitCheck.HasOverflowed() || (recursion_limit == 0)) { 72 if (stackLimitCheck.HasOverflowed() || (recursion_limit == 0)) {
71 return MaybeHandle<String>(); 73 return MaybeHandle<String>();
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 SealHandleScope shs(isolate); 755 SealHandleScope shs(isolate);
754 DCHECK_EQ(2, args.length()); 756 DCHECK_EQ(2, args.length());
755 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); 757 if (!args[0]->IsString()) return isolate->heap()->undefined_value();
756 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); 758 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value();
757 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); 759 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value();
758 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); 760 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate);
759 } 761 }
760 762
761 } // namespace internal 763 } // namespace internal
762 } // namespace v8 764 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698