Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Jul 25, 2022
1 parent 3ce9067 commit ed72463
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/Float16Array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class Float16Array {
const number = +value;

if (k < 0 || k >= length) {
throw new NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS);
throw NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS);
}

// don't use SpeciesConstructor
Expand Down Expand Up @@ -1050,32 +1050,23 @@ export class Float16Array {
}

let actualDeleteCount;
switch (arguments.length) {
case 0:
actualDeleteCount = 0;
break;

case 1:
actualDeleteCount = length - actualStart;
break;

default: {
const dc = ToIntegerOrInfinity(deleteCount);
if (dc < 0) {
actualDeleteCount = 0;
} else if (dc > length - actualStart) {
actualDeleteCount = length - actualStart;
} else {
actualDeleteCount = dc;
}
}
const argumentLength = arguments.length;
if (argumentLength === 0) {
actualDeleteCount = 0;
} else if (argumentLength === 1) {
actualDeleteCount = length - actualStart;
} else {
const dc = ToIntegerOrInfinity(deleteCount);
actualDeleteCount = dc < 0 ? 0 :
dc > length - actualStart ? length - actualStart : dc;
}

// don't use SpeciesConstructor
const newLength = length + insertCount - actualDeleteCount;
if (newLength > MAX_SAFE_INTEGER) {
throw NativeTypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED);
}

// don't use SpeciesConstructor
const proxy = new Float16Array(newLength);
const array = getFloat16BitsArray(proxy);

Expand Down

0 comments on commit ed72463

Please sign in to comment.