From 5b671e44b4deb70b0b136553817c759e7176bace Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 18 Mar 2018 20:43:06 +0100 Subject: [PATCH] Optimize IsSpecialConstant: directly use ConstantResolveResult instead of resolving the expression representing +Infty, -Infty and NaN of float and double. --- .../CSharp/Syntax/TypeSystemAstBuilder.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index e86971177..49c6372cf 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -549,26 +549,25 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax if (!UseSpecialConstants) { // +Infty, -Infty and NaN, cannot be represented in their encoded form. // Use an equivalent arithmetic expression instead. - var resolver = this.resolver ?? new CSharpResolver(type.GetDefinition().Compilation); if (info.Type == KnownTypeCode.Double) { switch ((double)constant) { case double.NegativeInfinity: // (-1.0 / 0.0) var left = new PrimitiveExpression(-1.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, -1.0)); var right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, double.NegativeInfinity)); return true; case double.PositiveInfinity: // (1.0 / 0.0) left = new PrimitiveExpression(1.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 1.0)); right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, double.PositiveInfinity)); return true; case double.NaN: // (0.0 / 0.0) left = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0)); right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, double.NaN)); return true; } } @@ -578,19 +577,19 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax var left = new PrimitiveExpression(-1.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, -1.0f)); var right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, float.NegativeInfinity)); return true; case float.PositiveInfinity: // (1.0f / 0.0f) left = new PrimitiveExpression(1.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 1.0f)); right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, float.PositiveInfinity)); return true; case float.NaN: // (0.0f / 0.0f) left = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f)); right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f)); expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction() - .WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult)); + .WithRR(new ConstantResolveResult(type, float.NaN)); return true; } }