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 4836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4847 if (data[start_pos] != 'I') { | 4847 if (data[start_pos] != 'I') { |
4848 return Heap::nan_value(); | 4848 return Heap::nan_value(); |
4849 } | 4849 } |
4850 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { | 4850 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { |
4851 // The maximal/minimal smi has 10 digits. If the string has less digits we | 4851 // The maximal/minimal smi has 10 digits. If the string has less digits we |
4852 // know it will fit into the smi-data type. | 4852 // know it will fit into the smi-data type. |
4853 int d = ParseDecimalInteger(data, start_pos, len); | 4853 int d = ParseDecimalInteger(data, start_pos, len); |
4854 if (minus) { | 4854 if (minus) { |
4855 if (d == 0) return Heap::minus_zero_value(); | 4855 if (d == 0) return Heap::minus_zero_value(); |
4856 d = -d; | 4856 d = -d; |
| 4857 } else if (!subject->HasHashCode() && |
| 4858 len <= String::kMaxArrayIndexSize && |
| 4859 (len == 1 || data[0] != '0')) { |
| 4860 // String hash is not calculated yet but all the data are present. |
| 4861 // Update the hash field to speed up sequential convertions. |
| 4862 uint32_t hash = StringHasher::MakeCachedArrayIndex(d, len); |
| 4863 #ifdef DEBUG |
| 4864 ASSERT((hash & String::kContainsCachedArrayIndexMask) == 0); |
| 4865 subject->Hash(); // Force hash calculation. |
| 4866 ASSERT_EQ(static_cast<int>(subject->hash_field()), |
| 4867 static_cast<int>(hash)); |
| 4868 #endif |
| 4869 subject->set_hash_field(hash); |
4857 } | 4870 } |
4858 return Smi::FromInt(d); | 4871 return Smi::FromInt(d); |
4859 } | 4872 } |
4860 } | 4873 } |
4861 | 4874 |
4862 // Slower case. | 4875 // Slower case. |
4863 return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX)); | 4876 return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX)); |
4864 } | 4877 } |
4865 | 4878 |
4866 | 4879 |
(...skipping 5859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10726 } else { | 10739 } else { |
10727 // Handle last resort GC and make sure to allow future allocations | 10740 // Handle last resort GC and make sure to allow future allocations |
10728 // to grow the heap without causing GCs (if possible). | 10741 // to grow the heap without causing GCs (if possible). |
10729 Counters::gc_last_resort_from_js.Increment(); | 10742 Counters::gc_last_resort_from_js.Increment(); |
10730 Heap::CollectAllGarbage(false); | 10743 Heap::CollectAllGarbage(false); |
10731 } | 10744 } |
10732 } | 10745 } |
10733 | 10746 |
10734 | 10747 |
10735 } } // namespace v8::internal | 10748 } } // namespace v8::internal |
OLD | NEW |