mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08: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
@ -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 New Issue
Block a user