mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-10 22:00:54 +01:00
Fold length operations when argument is a constant string (#141)
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
This commit is contained in:
parent
a80fc93646
commit
ad9b47b72f
2 changed files with 16 additions and 0 deletions
|
@ -2900,6 +2900,11 @@ struct Compiler
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprUnary::Len:
|
case AstExprUnary::Len:
|
||||||
|
if (arg.type == Constant::Type_String)
|
||||||
|
{
|
||||||
|
result.type = Constant::Type_Number;
|
||||||
|
result.valueNumber = double(arg.valueString.size);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1168,6 +1168,17 @@ RETURN R0 1
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("ConstantFoldStringLen")
|
||||||
|
{
|
||||||
|
CHECK_EQ("\n" + compileFunction0("return #'string', #'', #'a', #('b')"), R"(
|
||||||
|
LOADN R0 6
|
||||||
|
LOADN R1 0
|
||||||
|
LOADN R2 1
|
||||||
|
LOADN R3 1
|
||||||
|
RETURN R0 4
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("ConstantFoldCompare")
|
TEST_CASE("ConstantFoldCompare")
|
||||||
{
|
{
|
||||||
// ordered comparisons
|
// ordered comparisons
|
||||||
|
|
Loading…
Add table
Reference in a new issue