mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-12 21:10:37 +00: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;
|
||||
|
||||
case AstExprUnary::Len:
|
||||
if (arg.type == Constant::Type_String)
|
||||
{
|
||||
result.type = Constant::Type_Number;
|
||||
result.valueNumber = double(arg.valueString.size);
|
||||
}
|
||||
break;
|
||||
|
||||
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")
|
||||
{
|
||||
// ordered comparisons
|
||||
|
|
Loading…
Reference in a new issue