From b84a5b5fe7eba2fd4eef9dcc6edf7030d089b6c5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Sep 2019 15:17:40 +0200 Subject: [PATCH] Removed unnecessary cast/unbox opcode for static members --- .../Translation/Models/ReadableMember.GetValue.cs | 2 +- .../Translation/Models/ReadableMember.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs index 71306ce6..3b347f1d 100644 --- a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs +++ b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs @@ -47,7 +47,7 @@ namespace ComputeSharp.Shaders.Translation.Models // Load the argument (the object instance) and cast it to the right type il.Emit(OpCodes.Ldarg_0); - il.Emit(DeclaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass, DeclaringType); + if (!IsStatic) il.Emit(DeclaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass, DeclaringType); // Get the member value with the appropriate method if (Property != null) il.EmitCall(OpCodes.Callvirt, Property.GetMethod, null); diff --git a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs index 02c66f33..4fbd6b79 100644 --- a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs +++ b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs @@ -68,6 +68,20 @@ namespace ComputeSharp.Shaders.Translation.Models /// public string Name => (Field?.Name ?? Property?.Name) ?? throw new InvalidOperationException("Field and property can't both be null at the same time"); + /// + /// Gets whether or not the current member is not an instance member + /// + public bool IsStatic + { + get + { + if (Field != null) return Field.IsStatic; + if (Property != null) return Property.GetMethod.IsStatic; + + throw new InvalidOperationException("Field and property can't both be null at the same time"); + } + } + /// /// Converts a object into a instance ///