mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-03 18:30:54 +01:00
Merge 2700bd070c
into 26b2307a8b
This commit is contained in:
commit
43bc8a48b7
1 changed files with 33 additions and 0 deletions
|
@ -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
|
||||||
|
@ -72,6 +74,17 @@ static void foldUnary(Constant& result, AstExprUnary::Op op, const Constant& arg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int compareStrings(const char* string1, const char* string2, unsigned int size1, unsigned int size2)
|
||||||
|
{
|
||||||
|
unsigned int size = std::min(size1, size2);
|
||||||
|
|
||||||
|
int res = memcmp(string1, string2, size);
|
||||||
|
if (res != 0 || size1 == size2)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
return size1 < size2 ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& la, const Constant& ra)
|
static void foldBinary(Constant& result, AstExprBinary::Op op, const Constant& la, const Constant& ra)
|
||||||
{
|
{
|
||||||
switch (op)
|
switch (op)
|
||||||
|
@ -157,6 +170,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 = compareStrings(la.valueString, ra.valueString, la.stringLength, ra.stringLength) < 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareLe:
|
case AstExprBinary::CompareLe:
|
||||||
|
@ -165,6 +183,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 = compareStrings(la.valueString, ra.valueString, la.stringLength, ra.stringLength) <= 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareGt:
|
case AstExprBinary::CompareGt:
|
||||||
|
@ -173,6 +196,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 = compareStrings(la.valueString, ra.valueString, la.stringLength, ra.stringLength) > 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::CompareGe:
|
case AstExprBinary::CompareGe:
|
||||||
|
@ -181,6 +209,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 = compareStrings(la.valueString, ra.valueString, la.stringLength, ra.stringLength) >= 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstExprBinary::And:
|
case AstExprBinary::And:
|
||||||
|
|
Loading…
Add table
Reference in a new issue