Skip to content

Commit 0c059a4

Browse files
authored
refactor: simplify inline constant comparison
1 parent 005b4bf commit 0c059a4

1 file changed

Lines changed: 9 additions & 36 deletions

File tree

src/FastExpressionCompiler.LightExpression/FlatExpression.cs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,15 +2049,15 @@ private static bool AreConstantsEqual(ref ExprTree xTree, ref ExprNode x, ref Ex
20492049

20502050
return Type.GetTypeCode(x.Type) switch
20512051
{
2052-
TypeCode.Boolean => GetInlineBoolean(ref x) == GetInlineBoolean(ref y),
2053-
TypeCode.Byte => GetInlineByte(ref x) == GetInlineByte(ref y),
2054-
TypeCode.SByte => GetInlineSByte(ref x) == GetInlineSByte(ref y),
2055-
TypeCode.Char => GetInlineChar(ref x) == GetInlineChar(ref y),
2056-
TypeCode.Int16 => GetInlineInt16(ref x) == GetInlineInt16(ref y),
2057-
TypeCode.UInt16 => GetInlineUInt16(ref x) == GetInlineUInt16(ref y),
2058-
TypeCode.Int32 => GetInlineInt32(ref x) == GetInlineInt32(ref y),
2059-
TypeCode.UInt32 => GetInlineUInt32(ref x) == GetInlineUInt32(ref y),
2060-
TypeCode.Single => GetInlineSingle(ref x).Equals(GetInlineSingle(ref y)),
2052+
TypeCode.Boolean => x.InlineValue == y.InlineValue,
2053+
TypeCode.Byte => x.InlineValue == y.InlineValue,
2054+
TypeCode.SByte => x.InlineValue == y.InlineValue,
2055+
TypeCode.Char => x.InlineValue == y.InlineValue,
2056+
TypeCode.Int16 => x.InlineValue == y.InlineValue,
2057+
TypeCode.UInt16 => x.InlineValue == y.InlineValue,
2058+
TypeCode.Int32 => x.InlineValue == y.InlineValue,
2059+
TypeCode.UInt32 => x.InlineValue == y.InlineValue,
2060+
TypeCode.Single => FloatBits.ToFloat(x.InlineValue).Equals(FloatBits.ToFloat(y.InlineValue)),
20612061
_ => FlatExpressionThrow.UnsupportedInlineConstantType<bool>(x.Type)
20622062
};
20632063
}
@@ -2095,33 +2095,6 @@ private static int GetInlineConstantHashCode(Type type, uint data)
20952095
};
20962096
}
20972097

2098-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2099-
private static bool GetInlineBoolean(ref ExprNode node) => node.InlineValue != 0;
2100-
2101-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2102-
private static byte GetInlineByte(ref ExprNode node) => (byte)node.InlineValue;
2103-
2104-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2105-
private static sbyte GetInlineSByte(ref ExprNode node) => (sbyte)(byte)node.InlineValue;
2106-
2107-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2108-
private static char GetInlineChar(ref ExprNode node) => (char)(ushort)node.InlineValue;
2109-
2110-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2111-
private static short GetInlineInt16(ref ExprNode node) => (short)(ushort)node.InlineValue;
2112-
2113-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2114-
private static ushort GetInlineUInt16(ref ExprNode node) => (ushort)node.InlineValue;
2115-
2116-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2117-
private static int GetInlineInt32(ref ExprNode node) => (int)node.InlineValue;
2118-
2119-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2120-
private static uint GetInlineUInt32(ref ExprNode node) => node.InlineValue;
2121-
2122-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2123-
private static float GetInlineSingle(ref ExprNode node) => FloatBits.ToFloat(node.InlineValue);
2124-
21252098
private struct TraversalFrame
21262099
{
21272100
public readonly int XNextIdx;

0 commit comments

Comments
 (0)