OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <limits.h> | 5 #include <limits.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
11 #include "src/assert-scope.h" | 11 #include "src/assert-scope.h" |
12 #include "src/char-predicates-inl.h" | |
12 #include "src/conversions-inl.h" | 13 #include "src/conversions-inl.h" |
13 #include "src/conversions.h" | 14 #include "src/conversions.h" |
14 #include "src/dtoa.h" | 15 #include "src/dtoa.h" |
15 #include "src/factory.h" | 16 #include "src/factory.h" |
16 #include "src/list-inl.h" | 17 #include "src/list-inl.h" |
17 #include "src/strtod.h" | 18 #include "src/strtod.h" |
18 #include "src/utils.h" | 19 #include "src/utils.h" |
19 | 20 |
20 #ifndef _STLP_VENDOR_CSTD | 21 #ifndef _STLP_VENDOR_CSTD |
21 // STLPort doesn't import fpclassify into the std namespace. | 22 // STLPort doesn't import fpclassify into the std namespace. |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 return StringToDouble(unicode_cache, flat.ToOneByteVector(), flags, | 496 return StringToDouble(unicode_cache, flat.ToOneByteVector(), flags, |
496 empty_string_val); | 497 empty_string_val); |
497 } else { | 498 } else { |
498 return StringToDouble(unicode_cache, flat.ToUC16Vector(), flags, | 499 return StringToDouble(unicode_cache, flat.ToUC16Vector(), flags, |
499 empty_string_val); | 500 empty_string_val); |
500 } | 501 } |
501 } | 502 } |
502 } | 503 } |
503 | 504 |
504 | 505 |
506 bool IsNonArrayIndexInteger(String* string) { | |
507 const int kBufferSize = 64; | |
508 const int kUint32MaxChars = 11; | |
509 uint16_t buffer[kBufferSize]; | |
510 int offset = 0; | |
511 const int length = string->length(); | |
512 DCHECK_NE(0, length); | |
513 // First iteration, check for minus, 0 followed by anything else, etc. | |
514 { | |
515 int to = std::min(offset + kUint32MaxChars, length); | |
516 String::WriteToFlat(string, buffer, offset, to); | |
517 bool negative = false; | |
518 if (buffer[offset] == '-') { | |
519 negative = true; | |
520 ++offset; | |
521 if (offset == to) return false; // Just '-' is bad. | |
522 } | |
523 if (buffer[offset] == '0') { | |
524 ++offset; | |
525 return offset == 2 && offset == to; // Match just '-0'. | |
Toon Verwaest
2015/03/10 14:26:09
Quite some boilerplate pretending to be in a loop
| |
526 } | |
527 uint64_t acc = 0; | |
Toon Verwaest
2015/03/10 14:26:10
Wrap the entire "fast-path" into
if (!negative) {.
| |
528 for (; offset < to; ++offset) { | |
529 uint64_t digit = buffer[offset] - '0'; | |
530 if (digit > 9) return false; | |
531 acc = 10 * acc + digit; | |
532 } | |
533 // String is consumed. Evaluate what we have. | |
534 if (offset == length) { | |
535 if (negative) return true; | |
536 return acc > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()); | |
537 } | |
538 } | |
539 // Consume rest of string. If we get here, we're way out of uint32_t bounds. | |
540 while (offset != length) { | |
541 int to = std::min(offset + kBufferSize, length); | |
542 String::WriteToFlat(string, buffer, offset, to); | |
543 for (; offset < to; ++offset) { | |
544 if (!IsDecimalDigit(buffer[offset])) return false; | |
545 } | |
546 } | |
547 return true; | |
548 } | |
505 } } // namespace v8::internal | 549 } } // namespace v8::internal |
OLD | NEW |