| Index: sdk/lib/core/duration.dart
|
| diff --git a/sdk/lib/core/duration.dart b/sdk/lib/core/duration.dart
|
| index c081422ba850ca27423e0c5582c6bf96c2c9a7af..402d289e12d0c7414b434d6b970e2a32b863c824 100644
|
| --- a/sdk/lib/core/duration.dart
|
| +++ b/sdk/lib/core/duration.dart
|
| @@ -92,19 +92,24 @@ class Duration implements Comparable<Duration> {
|
| int seconds: 0,
|
| int milliseconds: 0,
|
| int microseconds: 0})
|
| - : _duration = days * MICROSECONDS_PER_DAY +
|
| - hours * MICROSECONDS_PER_HOUR +
|
| - minutes * MICROSECONDS_PER_MINUTE +
|
| - seconds * MICROSECONDS_PER_SECOND +
|
| - milliseconds * MICROSECONDS_PER_MILLISECOND +
|
| - microseconds;
|
| + : this._microseconds(
|
| + days * MICROSECONDS_PER_DAY +
|
| + hours * MICROSECONDS_PER_HOUR +
|
| + minutes * MICROSECONDS_PER_MINUTE +
|
| + seconds * MICROSECONDS_PER_SECOND +
|
| + milliseconds * MICROSECONDS_PER_MILLISECOND +
|
| + microseconds);
|
| +
|
| + // Fast path internal direct constructor to avoids the optional arguments and
|
| + // [_microseconds] recomputation.
|
| + const Duration._microseconds(this._duration);
|
|
|
| /**
|
| * Adds this Duration and [other] and
|
| * returns the sum as a new Duration object.
|
| */
|
| Duration operator +(Duration other) {
|
| - return new Duration(microseconds: _duration + other._duration);
|
| + return new Duration._microseconds(_duration + other._duration);
|
| }
|
|
|
| /**
|
| @@ -112,7 +117,7 @@ class Duration implements Comparable<Duration> {
|
| * returns the difference as a new Duration object.
|
| */
|
| Duration operator -(Duration other) {
|
| - return new Duration(microseconds: _duration - other._duration);
|
| + return new Duration._microseconds(_duration - other._duration);
|
| }
|
|
|
| /**
|
| @@ -123,7 +128,7 @@ class Duration implements Comparable<Duration> {
|
| * 53 bits, precision is lost because of double-precision arithmetic.
|
| */
|
| Duration operator *(num factor) {
|
| - return new Duration(microseconds: (_duration * factor).round());
|
| + return new Duration._microseconds((_duration * factor).round());
|
| }
|
|
|
| /**
|
| @@ -136,7 +141,7 @@ class Duration implements Comparable<Duration> {
|
| // By doing the check here instead of relying on "~/" below we get the
|
| // exception even with dart2js.
|
| if (quotient == 0) throw new IntegerDivisionByZeroException();
|
| - return new Duration(microseconds: _duration ~/ quotient);
|
| + return new Duration._microseconds(_duration ~/ quotient);
|
| }
|
|
|
| /**
|
| @@ -248,9 +253,7 @@ class Duration implements Comparable<Duration> {
|
| }
|
|
|
| if (inMicroseconds < 0) {
|
| - Duration duration =
|
| - new Duration(microseconds: -inMicroseconds);
|
| - return "-$duration";
|
| + return "-${-this}";
|
| }
|
| String twoDigitMinutes = twoDigits(inMinutes.remainder(MINUTES_PER_HOUR));
|
| String twoDigitSeconds = twoDigits(inSeconds.remainder(SECONDS_PER_MINUTE));
|
| @@ -274,7 +277,7 @@ class Duration implements Comparable<Duration> {
|
| * The returned `Duration` has the same length as this one, but is always
|
| * positive.
|
| */
|
| - Duration abs() => new Duration(microseconds: _duration.abs());
|
| + Duration abs() => new Duration._microseconds(_duration.abs());
|
|
|
| /**
|
| * Returns a new `Duration` representing this `Duration` negated.
|
| @@ -282,5 +285,5 @@ class Duration implements Comparable<Duration> {
|
| * The returned `Duration` has the same length as this one, but will have the
|
| * opposite sign of this one.
|
| */
|
| - Duration operator -() => new Duration(microseconds: -_duration);
|
| + Duration operator -() => new Duration._microseconds(-_duration);
|
| }
|
|
|