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

Side by Side Diff: src/runtime.cc

Issue 13045: * Changed search for single ASCII character to use memchr. (Closed)
Patch Set: Created 12 years 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 | « no previous file | 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 idx += shift; 1234 idx += shift;
1235 } 1235 }
1236 } while (idx <= n - m); 1236 } while (idx <= n - m);
1237 1237
1238 return -1; 1238 return -1;
1239 } 1239 }
1240 1240
1241 1241
1242 template <typename schar> 1242 template <typename schar>
1243 static int SingleCharIndexOf(Vector<const schar> string, 1243 static int SingleCharIndexOf(Vector<const schar> string,
1244 uc16 pattern_char, 1244 schar pattern_char,
1245 int start_index) { 1245 int start_index) {
1246 if (sizeof(schar) == 1 && pattern_char > String::kMaxAsciiCharCode) {
1247 return -1;
1248 }
1249 for (int i = start_index, n = string.length(); i < n; i++) { 1246 for (int i = start_index, n = string.length(); i < n; i++) {
1250 if (pattern_char == string[i]) { 1247 if (pattern_char == string[i]) {
1251 return i; 1248 return i;
1252 } 1249 }
1253 } 1250 }
1254 return -1; 1251 return -1;
1255 } 1252 }
1256 1253
1257 // Trivial string search for shorter strings. 1254 // Trivial string search for shorter strings.
1258 // On return, if "complete" is set to true, the return value is the 1255 // On return, if "complete" is set to true, the return value is the
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 FlattenString(sub); 1370 FlattenString(sub);
1374 sub_shape = StringShape(*sub); 1371 sub_shape = StringShape(*sub);
1375 } 1372 }
1376 StringShape pat_shape(*pat); 1373 StringShape pat_shape(*pat);
1377 // Searching for one specific character is common. For one 1374 // Searching for one specific character is common. For one
1378 // character patterns linear search is necessary, so any smart 1375 // character patterns linear search is necessary, so any smart
1379 // algorithm is unnecessary overhead. 1376 // algorithm is unnecessary overhead.
1380 if (pattern_length == 1) { 1377 if (pattern_length == 1) {
1381 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 1378 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
1382 if (sub_shape.IsAsciiRepresentation()) { 1379 if (sub_shape.IsAsciiRepresentation()) {
1383 return SingleCharIndexOf(sub->ToAsciiVector(), 1380 uc16 pchar = pat->Get(pat_shape, 0);
1384 pat->Get(pat_shape, 0), 1381 if (pchar > String::kMaxAsciiCharCode) {
1385 start_index); 1382 return -1;
1383 }
1384 Vector<const char> ascii_vector =
1385 sub->ToAsciiVector().SubVector(start_index, subject_length);
1386 void* pos = memchr(ascii_vector.start(),
1387 static_cast<const char>(pchar),
1388 static_cast<size_t>(ascii_vector.length()));
1389 if (pos == NULL) {
1390 return -1;
1391 }
1392 return reinterpret_cast<char*>(pos) - ascii_vector.start() + start_index;
1386 } 1393 }
1387 return SingleCharIndexOf(sub->ToUC16Vector(), 1394 return SingleCharIndexOf(sub->ToUC16Vector(),
1388 pat->Get(pat_shape, 0), 1395 pat->Get(pat_shape, 0),
1389 start_index); 1396 start_index);
1390 } 1397 }
1391 1398
1392 if (!pat->IsFlat(pat_shape)) { 1399 if (!pat->IsFlat(pat_shape)) {
1393 FlattenString(pat); 1400 FlattenString(pat);
1394 pat_shape = StringShape(*pat); 1401 pat_shape = StringShape(*pat);
1395 sub_shape = StringShape(*sub); 1402 sub_shape = StringShape(*sub);
(...skipping 4504 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 } else { 5907 } else {
5901 // Handle last resort GC and make sure to allow future allocations 5908 // Handle last resort GC and make sure to allow future allocations
5902 // to grow the heap without causing GCs (if possible). 5909 // to grow the heap without causing GCs (if possible).
5903 Counters::gc_last_resort_from_js.Increment(); 5910 Counters::gc_last_resort_from_js.Increment();
5904 Heap::CollectAllGarbage(); 5911 Heap::CollectAllGarbage();
5905 } 5912 }
5906 } 5913 }
5907 5914
5908 5915
5909 } } // namespace v8::internal 5916 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698