mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
constant fold string comparisons
This commit is contained in:
parent
6bfc38e61a
commit
931d8d619d
@ -6,6 +6,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
LUAU_FASTFLAGVARIABLE(LuauConstantFoldStringComparisons, false)
|
||||||
|
|
||||||
namespace Luau
|
namespace Luau
|
||||||
{
|
{
|
||||||
namespace Compile
|
namespace Compile
|
||||||
@ -157,6 +159,11 @@ static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& l
|
|||||||
result.type = Constant::Type_Boolean;
|
result.type = Constant::Type_Boolean;
|
||||||
result.valueBoolean = la.valueNumber < ra.valueNumber;
|
result.valueBoolean = la.valueNumber < ra.valueNumber;
|
||||||
}
|
}
|
||||||
|
else if (FFlag::LuauConstantFoldStringComparisons && la.type == Constant::Type_String && ra.type == Constant::Type_String)
|
||||||
|
{
|
||||||
|
result.type = Constant::Type_Boolean;
|
||||||
|
result.valueBoolean = strcmp(la.valueString, ra.valueString) < 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareLe:
|
case AstExprBinary::CompareLe:
|
||||||
@ -165,6 +172,11 @@ static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& l
|
|||||||
result.type = Constant::Type_Boolean;
|
result.type = Constant::Type_Boolean;
|
||||||
result.valueBoolean = la.valueNumber <= ra.valueNumber;
|
result.valueBoolean = la.valueNumber <= ra.valueNumber;
|
||||||
}
|
}
|
||||||
|
else if (FFlag::LuauConstantFoldStringComparisons && la.type == Constant::Type_String && ra.type == Constant::Type_String)
|
||||||
|
{
|
||||||
|
result.type = Constant::Type_Boolean;
|
||||||
|
result.valueBoolean = strcmp(la.valueString, ra.valueString) <= 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareGt:
|
case AstExprBinary::CompareGt:
|
||||||
@ -173,6 +185,11 @@ static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& l
|
|||||||
result.type = Constant::Type_Boolean;
|
result.type = Constant::Type_Boolean;
|
||||||
result.valueBoolean = la.valueNumber > ra.valueNumber;
|
result.valueBoolean = la.valueNumber > ra.valueNumber;
|
||||||
}
|
}
|
||||||
|
else if (FFlag::LuauConstantFoldStringComparisons && la.type == Constant::Type_String && ra.type == Constant::Type_String)
|
||||||
|
{
|
||||||
|
result.type = Constant::Type_Boolean;
|
||||||
|
result.valueBoolean = strcmp(la.valueString, ra.valueString) > 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareGe:
|
case AstExprBinary::CompareGe:
|
||||||
@ -181,6 +198,11 @@ static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& l
|
|||||||
result.type = Constant::Type_Boolean;
|
result.type = Constant::Type_Boolean;
|
||||||
result.valueBoolean = la.valueNumber >= ra.valueNumber;
|
result.valueBoolean = la.valueNumber >= ra.valueNumber;
|
||||||
}
|
}
|
||||||
|
else if (FFlag::LuauConstantFoldStringComparisons && la.type == Constant::Type_String && ra.type == Constant::Type_String)
|
||||||
|
{
|
||||||
|
result.type = Constant::Type_Boolean;
|
||||||
|
result.valueBoolean = strcmp(la.valueString, ra.valueString) >= 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::And:
|
case AstExprBinary::And:
|
||||||
|
Loading…
Reference in New Issue
Block a user