Optimize PrintStub logging function

This commit is contained in:
jduncanator 2018-12-10 12:47:28 +11:00
commit 32a0bb1594

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
@ -70,16 +71,17 @@ namespace Ryujinx.Common.Logging
public static void PrintStub<T>(LogClass logClass, T obj, [CallerMemberName] string caller = "") public static void PrintStub<T>(LogClass logClass, T obj, [CallerMemberName] string caller = "")
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
PropertyInfo[] props = typeof(T).GetProperties();
sb.Append("Stubbed. "); sb.Append("Stubbed. ");
foreach (var prop in typeof(T).GetProperties()) foreach (var prop in props)
{ {
sb.Append($"{prop.Name}: {prop.GetValue(obj)}"); sb.Append($"{prop.Name}: {prop.GetValue(obj)}");
sb.Append(" - "); sb.Append(" - ");
} }
if (typeof(T).GetProperties().Length > 0) if (props.Length > 0)
{ {
sb.Remove(sb.Length - 3, 3); sb.Remove(sb.Length - 3, 3);
} }
@ -90,18 +92,19 @@ namespace Ryujinx.Common.Logging
public static void PrintStub<T>(LogClass logClass, string message, T obj, [CallerMemberName] string caller = "") public static void PrintStub<T>(LogClass logClass, string message, T obj, [CallerMemberName] string caller = "")
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
PropertyInfo[] props = typeof(T).GetProperties();
sb.Append("Stubbed. "); sb.Append("Stubbed. ");
sb.Append(message); sb.Append(message);
sb.Append(' '); sb.Append(' ');
foreach (var prop in typeof(T).GetProperties()) foreach (var prop in props)
{ {
sb.Append($"{prop.Name}: {prop.GetValue(obj)}"); sb.Append($"{prop.Name}: {prop.GetValue(obj)}");
sb.Append(" - "); sb.Append(" - ");
} }
if (typeof(T).GetProperties().Length > 0) if (props.Length > 0)
{ {
sb.Remove(sb.Length - 3, 3); sb.Remove(sb.Length - 3, 3);
} }