@@ -891,14 +891,12 @@ final class JSUint8ArrayImpl extends JSIntegerArrayBase
891891
892892 @override
893893 JSUint8ArrayImpl sublist (int start, [int ? end]) {
894- final newOffset = offsetInBytes + start ;
895- final newEnd = RangeErrorUtils . checkValidRange (
896- newOffset,
897- end,
898- lengthInBytes ,
894+ final newEnd = RangeErrorUtils . checkValidRange (start, end, length) ;
895+ final newOffsetInBytes = offsetInBytes + start;
896+ final newLengthInBytes = newEnd - start;
897+ return JSUint8ArrayImpl ._(
898+ buffer. cloneAsDataView (newOffsetInBytes, newLengthInBytes) ,
899899 );
900- final newLength = newEnd - newOffset;
901- return JSUint8ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
902900 }
903901
904902 @override
@@ -999,14 +997,12 @@ final class JSInt8ArrayImpl extends JSIntegerArrayBase
999997
1000998 @override
1001999 JSInt8ArrayImpl sublist (int start, [int ? end]) {
1002- final newOffset = offsetInBytes + start ;
1003- final newEnd = RangeErrorUtils . checkValidRange (
1004- newOffset,
1005- end,
1006- lengthInBytes ,
1000+ final newEnd = RangeErrorUtils . checkValidRange (start, end, length) ;
1001+ final newOffsetInBytes = offsetInBytes + start;
1002+ final newLengthInBytes = newEnd - start;
1003+ return JSInt8ArrayImpl ._(
1004+ buffer. cloneAsDataView (newOffsetInBytes, newLengthInBytes) ,
10071005 );
1008- final newLength = newEnd - newOffset;
1009- return JSInt8ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
10101006 }
10111007
10121008 @override
@@ -1109,15 +1105,11 @@ final class JSUint8ClampedArrayImpl extends JSIntegerArrayBase
11091105
11101106 @override
11111107 JSUint8ClampedArrayImpl sublist (int start, [int ? end]) {
1112- final newOffset = offsetInBytes + start;
1113- final newEnd = RangeErrorUtils .checkValidRange (
1114- newOffset,
1115- end,
1116- lengthInBytes,
1117- );
1118- final newLength = newEnd - newOffset;
1108+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1109+ final newOffsetInBytes = offsetInBytes + start;
1110+ final newLengthInBytes = newEnd - start;
11191111 return JSUint8ClampedArrayImpl ._(
1120- buffer.cloneAsDataView (newOffset, newLength ),
1112+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes ),
11211113 );
11221114 }
11231115
@@ -1211,15 +1203,12 @@ final class JSUint16ArrayImpl extends JSIntegerArrayBase
12111203
12121204 @override
12131205 JSUint16ArrayImpl sublist (int start, [int ? end]) {
1214- final int newOffset = offsetInBytes + (start * 2 );
1215- final int newEnd = end == null ? lengthInBytes : end * 2 ;
1216- final int newLength = newEnd - newOffset;
1217- RangeErrorUtils .checkValidRange (
1218- newOffset ~ / 2 ,
1219- newEnd ~ / 2 ,
1220- lengthInBytes ~ / 2 ,
1206+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1207+ final newOffsetInBytes = offsetInBytes + 2 * start;
1208+ final newLengthInBytes = 2 * (newEnd - start);
1209+ return JSUint16ArrayImpl ._(
1210+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
12211211 );
1222- return JSUint16ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
12231212 }
12241213
12251214 @override
@@ -1327,15 +1316,12 @@ final class JSInt16ArrayImpl extends JSIntegerArrayBase
13271316
13281317 @override
13291318 JSInt16ArrayImpl sublist (int start, [int ? end]) {
1330- final int newOffset = offsetInBytes + (start * 2 );
1331- final int newEnd = end == null ? lengthInBytes : end * 2 ;
1332- final int newLength = newEnd - newOffset;
1333- RangeErrorUtils .checkValidRange (
1334- newOffset ~ / 2 ,
1335- newEnd ~ / 2 ,
1336- lengthInBytes ~ / 2 ,
1319+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1320+ final newOffsetInBytes = offsetInBytes + 2 * start;
1321+ final newLengthInBytes = 2 * (newEnd - start);
1322+ return JSInt16ArrayImpl ._(
1323+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
13371324 );
1338- return JSInt16ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
13391325 }
13401326
13411327 @override
@@ -1443,15 +1429,12 @@ final class JSUint32ArrayImpl extends JSIntegerArrayBase
14431429
14441430 @override
14451431 JSUint32ArrayImpl sublist (int start, [int ? end]) {
1446- final int newOffset = offsetInBytes + (start * 4 );
1447- final int newEnd = end == null ? lengthInBytes : end * 4 ;
1448- final int newLength = newEnd - newOffset;
1449- RangeErrorUtils .checkValidRange (
1450- newOffset ~ / 4 ,
1451- newEnd ~ / 4 ,
1452- lengthInBytes ~ / 4 ,
1432+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1433+ final newOffsetInBytes = offsetInBytes + 4 * start;
1434+ final newLengthInBytes = 4 * (newEnd - start);
1435+ return JSUint32ArrayImpl ._(
1436+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
14531437 );
1454- return JSUint32ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
14551438 }
14561439
14571440 @override
@@ -1559,15 +1542,12 @@ final class JSInt32ArrayImpl extends JSIntegerArrayBase
15591542
15601543 @override
15611544 JSInt32ArrayImpl sublist (int start, [int ? end]) {
1562- final int newOffset = offsetInBytes + (start * 4 );
1563- final int newEnd = end == null ? lengthInBytes : end * 4 ;
1564- final int newLength = newEnd - newOffset;
1565- RangeErrorUtils .checkValidRange (
1566- newOffset ~ / 4 ,
1567- newEnd ~ / 4 ,
1568- lengthInBytes ~ / 4 ,
1545+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1546+ final newOffsetInBytes = offsetInBytes + 4 * start;
1547+ final newLengthInBytes = 4 * (newEnd - start);
1548+ return JSInt32ArrayImpl ._(
1549+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
15691550 );
1570- return JSInt32ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
15711551 }
15721552
15731553 @override
@@ -1756,15 +1736,12 @@ final class JSBigUint64ArrayImpl extends JSIntegerArrayBase
17561736
17571737 @override
17581738 JSBigUint64ArrayImpl sublist (int start, [int ? end]) {
1759- final int newOffset = offsetInBytes + (start * 8 );
1760- final int newEnd = end == null ? lengthInBytes : end * 8 ;
1761- final int newLength = newEnd - newOffset;
1762- RangeErrorUtils .checkValidRange (
1763- newOffset ~ / 8 ,
1764- newEnd ~ / 8 ,
1765- lengthInBytes ~ / 8 ,
1739+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1740+ final newOffsetInBytes = offsetInBytes + 8 * start;
1741+ final newLengthInBytes = 8 * (newEnd - start);
1742+ return JSBigUint64ArrayImpl ._(
1743+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
17661744 );
1767- return JSBigUint64ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
17681745 }
17691746
17701747 @override
@@ -1860,15 +1837,12 @@ final class JSBigInt64ArrayImpl extends JSIntegerArrayBase
18601837
18611838 @override
18621839 JSBigInt64ArrayImpl sublist (int start, [int ? end]) {
1863- final int newOffset = offsetInBytes + (start * 8 );
1864- final int newEnd = end == null ? lengthInBytes : end * 8 ;
1865- final int newLength = newEnd - newOffset;
1866- RangeErrorUtils .checkValidRange (
1867- newOffset ~ / 8 ,
1868- newEnd ~ / 8 ,
1869- lengthInBytes ~ / 8 ,
1840+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
1841+ final newOffsetInBytes = offsetInBytes + 8 * start;
1842+ final newLengthInBytes = 8 * (newEnd - start);
1843+ return JSBigInt64ArrayImpl ._(
1844+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
18701845 );
1871- return JSBigInt64ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
18721846 }
18731847
18741848 @override
@@ -2321,15 +2295,12 @@ final class JSFloat32ArrayImpl extends JSFloatArrayBase
23212295
23222296 @override
23232297 JSFloat32ArrayImpl sublist (int start, [int ? end]) {
2324- final int newOffset = offsetInBytes + (start * 4 );
2325- final int newEnd = end == null ? lengthInBytes : end * 4 ;
2326- final int newLength = newEnd - newOffset;
2327- RangeErrorUtils .checkValidRange (
2328- newOffset ~ / 4 ,
2329- newEnd ~ / 4 ,
2330- lengthInBytes ~ / 4 ,
2298+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
2299+ final newOffsetInBytes = offsetInBytes + 4 * start;
2300+ final newLengthInBytes = 4 * (newEnd - start);
2301+ return JSFloat32ArrayImpl ._(
2302+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
23312303 );
2332- return JSFloat32ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
23332304 }
23342305
23352306 @override
@@ -2438,15 +2409,12 @@ final class JSFloat64ArrayImpl extends JSFloatArrayBase
24382409
24392410 @override
24402411 JSFloat64ArrayImpl sublist (int start, [int ? end]) {
2441- final int newOffset = offsetInBytes + (start * 8 );
2442- final int newEnd = end == null ? lengthInBytes : end * 8 ;
2443- final int newLength = newEnd - newOffset;
2444- RangeErrorUtils .checkValidRange (
2445- newOffset ~ / 8 ,
2446- newEnd ~ / 8 ,
2447- lengthInBytes ~ / 8 ,
2412+ final newEnd = RangeErrorUtils .checkValidRange (start, end, length);
2413+ final newOffsetInBytes = offsetInBytes + 8 * start;
2414+ final newLengthInBytes = 8 * (newEnd - start);
2415+ return JSFloat64ArrayImpl ._(
2416+ buffer.cloneAsDataView (newOffsetInBytes, newLengthInBytes),
24482417 );
2449- return JSFloat64ArrayImpl ._(buffer.cloneAsDataView (newOffset, newLength));
24502418 }
24512419
24522420 @override
0 commit comments