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

Side by Side Diff: src/regexp/regexp-utils.cc

Issue 2438283002: Revert of [regexp] Use consistent map checks for fast paths (Closed)
Patch Set: Created 4 years, 2 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/regexp-utils.h ('k') | src/runtime/runtime-regexp.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/regexp/regexp-utils.h" 5 #include "src/regexp/regexp-utils.h"
6 6
7 #include "src/factory.h" 7 #include "src/factory.h"
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 #include "src/objects-inl.h" 9 #include "src/objects-inl.h"
10 #include "src/regexp/jsregexp.h" 10 #include "src/regexp/jsregexp.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 Handle<Object> match; 129 Handle<Object> match;
130 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 130 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
131 isolate, match, 131 isolate, match,
132 JSObject::GetProperty(receiver, isolate->factory()->match_symbol()), 132 JSObject::GetProperty(receiver, isolate->factory()->match_symbol()),
133 Nothing<bool>()); 133 Nothing<bool>());
134 134
135 if (!match->IsUndefined(isolate)) return Just(match->BooleanValue()); 135 if (!match->IsUndefined(isolate)) return Just(match->BooleanValue());
136 return Just(object->IsJSRegExp()); 136 return Just(object->IsJSRegExp());
137 } 137 }
138 138
139 bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj) { 139 bool RegExpUtils::IsBuiltinExec(Handle<Object> exec) {
140 // TODO(ishell): Update this check once map changes for constant field 140 if (!exec->IsJSFunction()) return false;
141 // tracking are landing.
142 141
143 if (!obj->IsJSReceiver()) return false; 142 Code* code = Handle<JSFunction>::cast(exec)->code();
143 if (code == nullptr) return false;
144 144
145 JSReceiver* recv = JSReceiver::cast(*obj); 145 return (code->builtin_index() == Builtins::kRegExpPrototypeExec);
146
147 // Check the receiver's map.
148 Handle<JSFunction> regexp_function = isolate->regexp_function();
149 if (recv->map() != regexp_function->initial_map()) return false;
150
151 // Check the receiver's prototype's map.
152 Object* proto = recv->map()->prototype();
153 if (!proto->IsJSReceiver()) return false;
154
155 Handle<Map> initial_proto_initial_map = isolate->regexp_prototype_map();
156 return (JSReceiver::cast(proto)->map() == *initial_proto_initial_map);
157 } 146 }
158 147
159 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string, 148 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string,
160 int index, bool unicode) { 149 int index, bool unicode) {
161 if (unicode && index < string->length()) { 150 if (unicode && index < string->length()) {
162 const uint16_t first = string->Get(index); 151 const uint16_t first = string->Get(index);
163 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) { 152 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) {
164 const uint16_t second = string->Get(index + 1); 153 const uint16_t second = string->Get(index + 1);
165 if (second >= 0xDC00 && second <= 0xDFFF) { 154 if (second >= 0xDC00 && second <= 0xDFFF) {
166 return index + 2; 155 return index + 2;
(...skipping 18 matching lines...) Expand all
185 174
186 const int last_index = Handle<Smi>::cast(last_index_obj)->value(); 175 const int last_index = Handle<Smi>::cast(last_index_obj)->value();
187 const int new_last_index = 176 const int new_last_index =
188 AdvanceStringIndex(isolate, string, last_index, unicode); 177 AdvanceStringIndex(isolate, string, last_index, unicode);
189 178
190 return SetLastIndex(isolate, regexp, new_last_index); 179 return SetLastIndex(isolate, regexp, new_last_index);
191 } 180 }
192 181
193 } // namespace internal 182 } // namespace internal
194 } // namespace v8 183 } // namespace v8
OLDNEW
« no previous file with comments | « src/regexp/regexp-utils.h ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698