| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 2335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 } | 2346 } |
| 2347 | 2347 |
| 2348 return -1; | 2348 return -1; |
| 2349 } | 2349 } |
| 2350 | 2350 |
| 2351 | 2351 |
| 2352 template <typename schar> | 2352 template <typename schar> |
| 2353 static inline int SingleCharIndexOf(Vector<const schar> string, | 2353 static inline int SingleCharIndexOf(Vector<const schar> string, |
| 2354 schar pattern_char, | 2354 schar pattern_char, |
| 2355 int start_index) { | 2355 int start_index) { |
| 2356 if (sizeof(schar) == 1) { |
| 2357 schar* pos = reinterpret_cast<schar*>( |
| 2358 memchr(string.start() + start_index, |
| 2359 pattern_char, |
| 2360 string.length() - start_index)); |
| 2361 if (pos == NULL) return -1; |
| 2362 return pos - string.start(); |
| 2363 } |
| 2356 for (int i = start_index, n = string.length(); i < n; i++) { | 2364 for (int i = start_index, n = string.length(); i < n; i++) { |
| 2357 if (pattern_char == string[i]) { | 2365 if (pattern_char == string[i]) { |
| 2358 return i; | 2366 return i; |
| 2359 } | 2367 } |
| 2360 } | 2368 } |
| 2361 return -1; | 2369 return -1; |
| 2362 } | 2370 } |
| 2363 | 2371 |
| 2364 | 2372 |
| 2365 template <typename schar> | 2373 template <typename schar> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2393 | 2401 |
| 2394 // We know our pattern is at least 2 characters, we cache the first so | 2402 // We know our pattern is at least 2 characters, we cache the first so |
| 2395 // the common case of the first character not matching is faster. | 2403 // the common case of the first character not matching is faster. |
| 2396 pchar pattern_first_char = pattern[0]; | 2404 pchar pattern_first_char = pattern[0]; |
| 2397 for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { | 2405 for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { |
| 2398 badness++; | 2406 badness++; |
| 2399 if (badness > 0) { | 2407 if (badness > 0) { |
| 2400 *complete = false; | 2408 *complete = false; |
| 2401 return i; | 2409 return i; |
| 2402 } | 2410 } |
| 2403 if (subject[i] != pattern_first_char) continue; | 2411 if (sizeof(schar) == 1 && sizeof(pchar) == 1) { |
| 2412 schar* pos = reinterpret_cast<schar*>(memchr(subject.start() + i, |
| 2413 pattern_first_char, |
| 2414 n - i + 1)); |
| 2415 if (pos == NULL) { |
| 2416 *complete = true; |
| 2417 return -1; |
| 2418 } |
| 2419 i = pos - subject.start(); |
| 2420 } else { |
| 2421 if (subject[i] != pattern_first_char) continue; |
| 2422 } |
| 2404 int j = 1; | 2423 int j = 1; |
| 2405 do { | 2424 do { |
| 2406 if (pattern[j] != subject[i+j]) { | 2425 if (pattern[j] != subject[i+j]) { |
| 2407 break; | 2426 break; |
| 2408 } | 2427 } |
| 2409 j++; | 2428 j++; |
| 2410 } while (j < pattern.length()); | 2429 } while (j < pattern.length()); |
| 2411 if (j == pattern.length()) { | 2430 if (j == pattern.length()) { |
| 2412 *complete = true; | 2431 *complete = true; |
| 2413 return i; | 2432 return i; |
| 2414 } | 2433 } |
| 2415 badness += j; | 2434 badness += j; |
| 2416 } | 2435 } |
| 2417 *complete = true; | 2436 *complete = true; |
| 2418 return -1; | 2437 return -1; |
| 2419 } | 2438 } |
| 2420 | 2439 |
| 2421 // Simple indexOf that never bails out. For short patterns only. | 2440 // Simple indexOf that never bails out. For short patterns only. |
| 2422 template <typename pchar, typename schar> | 2441 template <typename pchar, typename schar> |
| 2423 static int SimpleIndexOf(Vector<const schar> subject, | 2442 static int SimpleIndexOf(Vector<const schar> subject, |
| 2424 Vector<const pchar> pattern, | 2443 Vector<const pchar> pattern, |
| 2425 int idx) { | 2444 int idx) { |
| 2426 pchar pattern_first_char = pattern[0]; | 2445 pchar pattern_first_char = pattern[0]; |
| 2427 for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { | 2446 for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { |
| 2428 if (subject[i] != pattern_first_char) continue; | 2447 if (sizeof(schar) == 1 && sizeof(pchar) == 1) { |
| 2448 schar* pos = reinterpret_cast<schar*>(memchr(subject.start() + i, |
| 2449 pattern_first_char, |
| 2450 n - i + 1)); |
| 2451 if (pos == NULL) return -1; |
| 2452 i = pos - subject.start(); |
| 2453 } else { |
| 2454 if (subject[i] != pattern_first_char) continue; |
| 2455 } |
| 2429 int j = 1; | 2456 int j = 1; |
| 2430 do { | 2457 do { |
| 2431 if (pattern[j] != subject[i+j]) { | 2458 if (pattern[j] != subject[i+j]) { |
| 2432 break; | 2459 break; |
| 2433 } | 2460 } |
| 2434 j++; | 2461 j++; |
| 2435 } while (j < pattern.length()); | 2462 } while (j < pattern.length()); |
| 2436 if (j == pattern.length()) { | 2463 if (j == pattern.length()) { |
| 2437 return i; | 2464 return i; |
| 2438 } | 2465 } |
| (...skipping 6934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9373 } else { | 9400 } else { |
| 9374 // Handle last resort GC and make sure to allow future allocations | 9401 // Handle last resort GC and make sure to allow future allocations |
| 9375 // to grow the heap without causing GCs (if possible). | 9402 // to grow the heap without causing GCs (if possible). |
| 9376 Counters::gc_last_resort_from_js.Increment(); | 9403 Counters::gc_last_resort_from_js.Increment(); |
| 9377 Heap::CollectAllGarbage(false); | 9404 Heap::CollectAllGarbage(false); |
| 9378 } | 9405 } |
| 9379 } | 9406 } |
| 9380 | 9407 |
| 9381 | 9408 |
| 9382 } } // namespace v8::internal | 9409 } } // namespace v8::internal |
| OLD | NEW |