1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-24 21:48:35 +01:00

Compare commits

..

No commits in common. "51833d523dc750caba0f74bc9130559a5071d0fa" and "db7ee04d30e78adb9b60d8248240b09d18afa491" have entirely different histories.

3 changed files with 13 additions and 17 deletions

View file

@ -45,7 +45,6 @@ Additions
Improvements Improvements
- Improved RawContentManager's reader loading and added better exception handling - Improved RawContentManager's reader loading and added better exception handling
- Improved CopyExtensions construction speed
## 5.0.0 ## 5.0.0
### MLEM ### MLEM

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -10,7 +9,6 @@ namespace MLEM.Data {
public static class CopyExtensions { public static class CopyExtensions {
private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
private static readonly Dictionary<Type, ConstructorInfo> ConstructorCache = new Dictionary<Type, ConstructorInfo>();
/// <summary> /// <summary>
/// Creates a shallow copy of the object and returns it. /// Creates a shallow copy of the object and returns it.
@ -87,10 +85,9 @@ namespace MLEM.Data {
} }
private static object Construct(Type t, BindingFlags flags) { private static object Construct(Type t, BindingFlags flags) {
if (!ConstructorCache.TryGetValue(t, out var constructor)) {
var constructors = t.GetConstructors(flags); var constructors = t.GetConstructors(flags);
// find a contructor with the correct attribute // find a contructor with the correct attribute
constructor = constructors.FirstOrDefault(c => c.GetCustomAttribute<CopyConstructorAttribute>() != null); var constructor = constructors.FirstOrDefault(c => c.GetCustomAttribute<CopyConstructorAttribute>() != null);
// find a parameterless construcotr // find a parameterless construcotr
if (constructor == null) if (constructor == null)
constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null); constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null);
@ -99,8 +96,6 @@ namespace MLEM.Data {
constructor = constructors.FirstOrDefault(); constructor = constructors.FirstOrDefault();
if (constructor == null) if (constructor == null)
throw new NullReferenceException($"Type {t} does not have a constructor with the required visibility"); throw new NullReferenceException($"Type {t} does not have a constructor with the required visibility");
ConstructorCache.Add(t, constructor);
}
return constructor.Invoke(new object[constructor.GetParameters().Length]); return constructor.Invoke(new object[constructor.GetParameters().Length]);
} }

View file

@ -1,6 +1,8 @@
using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Font;
namespace MLEM.Ui.Style { namespace MLEM.Ui.Style {
/// <summary> /// <summary>