mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Fold length operations when argument is a constant string
Change is very self-explanatory, it seems a little odd this wasn't already added so if there is a reason that this doesn't already exist please say 👍
This commit is contained in:
parent
98fa75e911
commit
d35c4e7b7d
1 changed files with 5 additions and 2 deletions
|
@ -2892,10 +2892,13 @@ struct Compiler
|
||||||
result.valueNumber = -arg.valueNumber;
|
result.valueNumber = -arg.valueNumber;
|
||||||
}
|
}
|
||||||
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:
|
||||||
LUAU_ASSERT(!"Unexpected unary operation");
|
LUAU_ASSERT(!"Unexpected unary operation");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue