| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2012 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> | 3 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 LChar* end = m_buffer + WTF_ARRAY_LENGTH(m_buffer); | 43 LChar* end = m_buffer + WTF_ARRAY_LENGTH(m_buffer); |
| 44 m_begin = end; | 44 m_begin = end; |
| 45 | 45 |
| 46 // We need to switch to the unsigned type when negating the value since | 46 // We need to switch to the unsigned type when negating the value since |
| 47 // abs(INT_MIN) == INT_MAX + 1. | 47 // abs(INT_MIN) == INT_MAX + 1. |
| 48 bool isNegative = base::IsValueNegative(input); | 48 bool isNegative = base::IsValueNegative(input); |
| 49 UnsignedIntegerType value = isNegative ? 0u - input : input; | 49 UnsignedIntegerType value = isNegative ? 0u - input : input; |
| 50 | 50 |
| 51 do { | 51 do { |
| 52 --m_begin; | 52 --m_begin; |
| 53 ASSERT(m_begin != m_buffer); | 53 DCHECK_NE(m_begin, m_buffer); |
| 54 *m_begin = static_cast<LChar>((value % 10) + '0'); | 54 *m_begin = static_cast<LChar>((value % 10) + '0'); |
| 55 value /= 10; | 55 value /= 10; |
| 56 } while (value); | 56 } while (value); |
| 57 | 57 |
| 58 if (isNegative) { | 58 if (isNegative) { |
| 59 --m_begin; | 59 --m_begin; |
| 60 ASSERT(m_begin != m_buffer); | 60 DCHECK_NE(m_begin, m_buffer); |
| 61 *m_begin = static_cast<LChar>('-'); | 61 *m_begin = static_cast<LChar>('-'); |
| 62 } | 62 } |
| 63 | 63 |
| 64 m_length = static_cast<unsigned>(end - m_begin); | 64 m_length = static_cast<unsigned>(end - m_begin); |
| 65 } | 65 } |
| 66 | 66 |
| 67 const LChar* characters8() const { return m_begin; } | 67 const LChar* characters8() const { return m_begin; } |
| 68 unsigned length() const { return m_length; } | 68 unsigned length() const { return m_length; } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 using UnsignedIntegerType = typename std::make_unsigned<IntegerType>::type; | 71 using UnsignedIntegerType = typename std::make_unsigned<IntegerType>::type; |
| 72 static const size_t kBufferSize = 3 * sizeof(UnsignedIntegerType) + | 72 static const size_t kBufferSize = 3 * sizeof(UnsignedIntegerType) + |
| 73 std::numeric_limits<IntegerType>::is_signed; | 73 std::numeric_limits<IntegerType>::is_signed; |
| 74 | 74 |
| 75 LChar m_buffer[kBufferSize]; | 75 LChar m_buffer[kBufferSize]; |
| 76 LChar* m_begin; | 76 LChar* m_begin; |
| 77 unsigned m_length; | 77 unsigned m_length; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace WTF | 80 } // namespace WTF |
| 81 | 81 |
| 82 #endif // IntegerToStringConversion_h | 82 #endif // IntegerToStringConversion_h |
| OLD | NEW |