From 7ba110252d3ffe9ef611e2f1dd33f5cd1b22c6e1 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 21 Jun 2024 13:55:59 +0100 Subject: [PATCH] Cleanup NumberFormater --- .../CodeGen/Msl/NumberFormatter.cs | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/NumberFormatter.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/NumberFormatter.cs index f086e74366..63ecbc0aa9 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/NumberFormatter.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/NumberFormatter.cs @@ -10,25 +10,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl public static bool TryFormat(int value, AggregateType dstType, out string formatted) { - if (dstType == AggregateType.FP32) + switch (dstType) { - return TryFormatFloat(BitConverter.Int32BitsToSingle(value), out formatted); - } - else if (dstType == AggregateType.S32) - { - formatted = FormatInt(value); - } - else if (dstType == AggregateType.U32) - { - formatted = FormatUint((uint)value); - } - else if (dstType == AggregateType.Bool) - { - formatted = value != 0 ? "true" : "false"; - } - else - { - throw new ArgumentException($"Invalid variable type \"{dstType}\"."); + case AggregateType.FP32: + return TryFormatFloat(BitConverter.Int32BitsToSingle(value), out formatted); + case AggregateType.S32: + formatted = FormatInt(value); + break; + case AggregateType.U32: + formatted = FormatUint((uint)value); + break; + case AggregateType.Bool: + formatted = value != 0 ? "true" : "false"; + break; + default: + throw new ArgumentException($"Invalid variable type \"{dstType}\"."); } return true; @@ -65,18 +61,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl public static string FormatInt(int value, AggregateType dstType) { - if (dstType == AggregateType.S32) + return dstType switch { - return FormatInt(value); - } - else if (dstType == AggregateType.U32) - { - return FormatUint((uint)value); - } - else - { - throw new ArgumentException($"Invalid variable type \"{dstType}\"."); - } + AggregateType.S32 => FormatInt(value), + AggregateType.U32 => FormatUint((uint)value), + _ => throw new ArgumentException($"Invalid variable type \"{dstType}\".") + }; } public static string FormatInt(int value)