Skip to content

Commit 3b947da

Browse files
committed
Remove unnecessary number index casts
1 parent 67cb7cf commit 3b947da

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/compiler/iroptimizer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ class IROptimizer {
164164
return InputType.NUMBER;
165165
}
166166

167+
case InputOpcode.CAST_NUMBER_INDEX: {
168+
const innerType = inputs.target.type;
169+
if (innerType & InputType.NUMBER_INDEX) return innerType;
170+
return InputType.NUMBER_INDEX;
171+
}
172+
167173
case InputOpcode.CAST_NUMBER_OR_NAN: {
168174
const innerType = inputs.target.type;
169175
if (innerType & InputType.NUMBER_OR_NAN) return innerType;
@@ -709,6 +715,14 @@ class IROptimizer {
709715
return input;
710716
}
711717

718+
case InputOpcode.CAST_NUMBER_INDEX: {
719+
const targetType = input.inputs.target.type;
720+
if ((targetType & InputType.NUMBER_INDEX) === targetType) {
721+
return input.inputs.target;
722+
}
723+
return input;
724+
}
725+
712726
case InputOpcode.CAST_NUMBER_OR_NAN: {
713727
const targetType = input.inputs.target.type;
714728
if ((targetType & InputType.NUMBER_OR_NAN) === targetType) {

test/snapshot/__snapshots__/tw-simple-string-operations.sb3.tw-snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ b0.value = "ababa";
2525
b1.value = "";
2626
b2.value = 1;
2727
for (var a0 = b0.value.length; a0 > 0; a0--) {
28-
if ((((b0.value)[(b2.value | 0) - 1] || "").toLowerCase() === "a".toLowerCase())) {
28+
if ((((b0.value)[b2.value - 1] || "").toLowerCase() === "a".toLowerCase())) {
2929
b1.value = (b1.value + "b");
3030
} else {
3131
b1.value = (b1.value + "a");

0 commit comments

Comments
 (0)