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

Side by Side Diff: src/objects.cc

Issue 2176553002: Move StringMatch to String::IndexOf (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 4 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/objects.h ('k') | src/runtime/runtime-strings.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 11189 matching lines...) Expand 10 before | Expand all | Expand 10 after
11200 } 11200 }
11201 } 11201 }
11202 if (r < 0) { 11202 if (r < 0) {
11203 result = ComparisonResult::kLessThan; 11203 result = ComparisonResult::kLessThan;
11204 } else if (r > 0) { 11204 } else if (r > 0) {
11205 result = ComparisonResult::kGreaterThan; 11205 result = ComparisonResult::kGreaterThan;
11206 } 11206 }
11207 return result; 11207 return result;
11208 } 11208 }
11209 11209
11210 int String::IndexOf(Isolate* isolate, Handle<String> sub, Handle<String> pat,
11211 int start_index) {
11212 DCHECK(0 <= start_index);
11213 DCHECK(start_index <= sub->length());
11214
11215 int pattern_length = pat->length();
11216 if (pattern_length == 0) return start_index;
11217
11218 int subject_length = sub->length();
11219 if (start_index + pattern_length > subject_length) return -1;
11220
11221 sub = String::Flatten(sub);
11222 pat = String::Flatten(pat);
11223
11224 DisallowHeapAllocation no_gc; // ensure vectors stay valid
11225 // Extract flattened substrings of cons strings before getting encoding.
11226 String::FlatContent seq_sub = sub->GetFlatContent();
11227 String::FlatContent seq_pat = pat->GetFlatContent();
11228
11229 // dispatch on type of strings
11230 if (seq_pat.IsOneByte()) {
11231 Vector<const uint8_t> pat_vector = seq_pat.ToOneByteVector();
11232 if (seq_sub.IsOneByte()) {
11233 return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
11234 start_index);
11235 }
11236 return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector,
11237 start_index);
11238 }
11239 Vector<const uc16> pat_vector = seq_pat.ToUC16Vector();
11240 if (seq_sub.IsOneByte()) {
11241 return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
11242 start_index);
11243 }
11244 return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector, start_index);
11245 }
11210 11246
11211 bool String::IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match) { 11247 bool String::IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match) {
11212 int slen = length(); 11248 int slen = length();
11213 // Can't check exact length equality, but we can check bounds. 11249 // Can't check exact length equality, but we can check bounds.
11214 int str_len = str.length(); 11250 int str_len = str.length();
11215 if (!allow_prefix_match && 11251 if (!allow_prefix_match &&
11216 (str_len < slen || 11252 (str_len < slen ||
11217 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize))) { 11253 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize))) {
11218 return false; 11254 return false;
11219 } 11255 }
(...skipping 7725 matching lines...) Expand 10 before | Expand all | Expand 10 after
18945 18981
18946 Object* data_obj = 18982 Object* data_obj =
18947 constructor->shared()->get_api_func_data()->access_check_info(); 18983 constructor->shared()->get_api_func_data()->access_check_info();
18948 if (data_obj->IsUndefined(isolate)) return nullptr; 18984 if (data_obj->IsUndefined(isolate)) return nullptr;
18949 18985
18950 return AccessCheckInfo::cast(data_obj); 18986 return AccessCheckInfo::cast(data_obj);
18951 } 18987 }
18952 18988
18953 } // namespace internal 18989 } // namespace internal
18954 } // namespace v8 18990 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698