| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _Double extends _Num implements double { | 5 class _Double implements double { |
| 6 factory _Double.fromInteger(int value) | 6 factory _Double.fromInteger(int value) |
| 7 native "Double_doubleFromInteger"; | 7 native "Double_doubleFromInteger"; |
| 8 | 8 |
| 9 Type get runtimeType => double; | 9 Type get runtimeType => double; |
| 10 | 10 |
| 11 int get _identityHashCode { | 11 int get _identityHashCode { |
| 12 if (isNaN || isInfinite) return 0; | 12 if (isNaN || isInfinite) return 0; |
| 13 return toInt(); | 13 return toInt(); |
| 14 } | 14 } |
| 15 double operator +(num other) { | 15 double operator +(num other) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 num _toBigintOrDouble() { return this; } | 133 num _toBigintOrDouble() { return this; } |
| 134 double toDouble() { return this; } | 134 double toDouble() { return this; } |
| 135 | 135 |
| 136 static const int CACHE_SIZE_LOG2 = 3; | 136 static const int CACHE_SIZE_LOG2 = 3; |
| 137 static const int CACHE_LENGTH = 1 << (CACHE_SIZE_LOG2 + 1); | 137 static const int CACHE_LENGTH = 1 << (CACHE_SIZE_LOG2 + 1); |
| 138 static const int CACHE_MASK = CACHE_LENGTH - 1; | 138 static const int CACHE_MASK = CACHE_LENGTH - 1; |
| 139 // Each key (double) followed by its toString result. | 139 // Each key (double) followed by its toString result. |
| 140 static final List _cache = new List(CACHE_LENGTH); | 140 static final List _cache = new List(CACHE_LENGTH); |
| 141 static int _cacheEvictIndex = 0; | 141 static int _cacheEvictIndex = 0; |
| 142 | 142 |
| 143 String _toString() native "Double_toString"; |
| 144 |
| 143 String toString() { | 145 String toString() { |
| 144 // TODO(koda): Consider starting at most recently inserted. | 146 // TODO(koda): Consider starting at most recently inserted. |
| 145 for (int i = 0; i < CACHE_LENGTH; i += 2) { | 147 for (int i = 0; i < CACHE_LENGTH; i += 2) { |
| 146 // Need 'identical' to handle negative zero, etc. | 148 // Need 'identical' to handle negative zero, etc. |
| 147 if (identical(_cache[i], this)) { | 149 if (identical(_cache[i], this)) { |
| 148 return _cache[i + 1]; | 150 return _cache[i + 1]; |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 // TODO(koda): Consider optimizing all small integral values. | 153 // TODO(koda): Consider optimizing all small integral values. |
| 152 if (identical(0.0, this)) { | 154 if (identical(0.0, this)) { |
| 153 return "0.0"; | 155 return "0.0"; |
| 154 } | 156 } |
| 155 String result = super.toString(); | 157 String result = _toString(); |
| 156 // Replace the least recently inserted entry. | 158 // Replace the least recently inserted entry. |
| 157 _cache[_cacheEvictIndex] = this; | 159 _cache[_cacheEvictIndex] = this; |
| 158 _cache[_cacheEvictIndex + 1] = result; | 160 _cache[_cacheEvictIndex + 1] = result; |
| 159 _cacheEvictIndex = (_cacheEvictIndex + 2) & CACHE_MASK; | 161 _cacheEvictIndex = (_cacheEvictIndex + 2) & CACHE_MASK; |
| 160 return result; | 162 return result; |
| 161 } | 163 } |
| 162 | 164 |
| 163 String toStringAsFixed(int fractionDigits) { | 165 String toStringAsFixed(int fractionDigits) { |
| 164 // See ECMAScript-262, 15.7.4.5 for details. | 166 // See ECMAScript-262, 15.7.4.5 for details. |
| 165 | 167 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 return EQUAL; | 262 return EQUAL; |
| 261 } | 263 } |
| 262 } else if (isNaN) { | 264 } else if (isNaN) { |
| 263 return other.isNaN ? EQUAL : GREATER; | 265 return other.isNaN ? EQUAL : GREATER; |
| 264 } else { | 266 } else { |
| 265 // Other is NaN. | 267 // Other is NaN. |
| 266 return LESS; | 268 return LESS; |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 } | 271 } |
| OLD | NEW |