Skip to content

Commit a4dc873

Browse files
authored
Implement Int64 as a wrapper for int when targeting native and Wasm (#905)
This PR adds another `Int64` implementation that is just a wrapper around `int`, to be used in targets where `int` is 64 bits. Because `dart doc` generates using the native class, all documentation comments are moved to the native class. The conditional import is implemented based on availability of the library `dart:html`, which is only available on dart2js. Improves #172. It could be further improved by having `Int64` as an extension class when targeting native and Wasm, but that would be a breaking change, and we would have to remove the `IntX` superclass as extensions cannot extend or implement other classes.
1 parent 1aa58ef commit a4dc873

File tree

8 files changed

+1396
-1139
lines changed

8 files changed

+1396
-1139
lines changed

pkgs/fixnum/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
like `sortedBy` in the platform libraries.
66
* Run `dart format` with the new style.
77
* Require Dart 3.4
8+
* Improve `Int64` representation when compiling to native or Wasm.
89

910
## 1.1.1
1011

pkgs/fixnum/lib/fixnum.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/// Signed 32- and 64-bit integer support.
66
///
7-
/// The integer implementations in this library are designed to work
8-
/// identically whether executed on the Dart VM or compiled to JavaScript.
7+
/// The integer implementations in this library are designed to work identically
8+
/// whether executed on the Dart VM or compiled to JavaScript or Wasm.
99
library;
1010

1111
export 'src/int32.dart';

pkgs/fixnum/lib/src/int32.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ class Int32 implements IntX {
321321
return Int32(value);
322322
}
323323

324-
/// Returns [:true:] if this [Int32] has the same numeric value as the
325-
/// given object. The argument may be an [int] or an [IntX].
326324
@override
327325
bool operator ==(Object other) {
328326
if (other is Int32) {
@@ -437,10 +435,10 @@ class Int32 implements IntX {
437435
@override
438436
List<int> toBytes() {
439437
var result = List<int>.filled(4, 0);
440-
result[0] = _i & 0xff;
441-
result[1] = (_i >> 8) & 0xff;
442-
result[2] = (_i >> 16) & 0xff;
443438
result[3] = (_i >> 24) & 0xff;
439+
result[2] = (_i >> 16) & 0xff;
440+
result[1] = (_i >> 8) & 0xff;
441+
result[0] = _i & 0xff;
444442
return result;
445443
}
446444

0 commit comments

Comments
 (0)