Chromium Code Reviews| Index: runtime/lib/integers.cc |
| diff --git a/runtime/lib/integers.cc b/runtime/lib/integers.cc |
| index 84dc9d6205fa1c82c40e82ebc78b3aff4ceb2af8..3bdd21c62b2fd529561623b25169e367f93c9dd1 100644 |
| --- a/runtime/lib/integers.cc |
| +++ b/runtime/lib/integers.cc |
| @@ -344,6 +344,37 @@ DEFINE_NATIVE_ENTRY(Smi_bitLength, 1) { |
| return Smi::New(result); |
| } |
| +DEFINE_NATIVE_ENTRY(Smi_toString, 1) { |
| + const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); |
| + if (FLAG_trace_intrinsified_natives) { |
| + OS::Print("Smi_toString: %s\n", operand.ToCString()); |
| + } |
| + // Maximal number of digits of a 63 bit number is 19. Add one for minus sign. |
|
Lasse Reichstein Nielsen
2013/09/23 11:25:18
I decided against using OS::SNPrint(characters, 0,
|
| + const size_t kMaxLength = 20; |
| + uint8_t characters[kMaxLength]; |
| + uint8_t* end = characters + kMaxLength; |
| + uint8_t* cursor = end; |
| + bool negative = false; |
| + int64_t signed_value = operand.AsInt64Value(); |
| + uint64_t value; |
| + if (signed_value < 0) { |
| + negative = true; |
| + value = -signed_value; |
| + } else { |
| + value = signed_value; |
| + } |
| + do { |
| + uint64_t digit = value % 10; |
| + value = (value - digit) / 10; |
| + *--cursor = '0' + digit; |
| + } while (value); |
| + if (negative) { |
| + *--cursor = '-'; |
| + } |
| + intptr_t length = static_cast<intptr_t>(end - cursor); |
| + return OneByteString::New(cursor, length, Heap::kNew); |
| +} |
| + |
| // Mint natives. |