mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-22 08:08:51 -05:00
Reduced debug overhead of Events (#435)
* fix: memory allocations due to boxing when creating a StackTraceEntry with disabled DebugMode. fix: slow repeaded lookups of EditorPrefs for determining DebugMode * Cleaning up code that was affected by work on #434 - removed dead code - fixed formatting Commit-Type: Refactor
This commit is contained in:
parent
4576277a19
commit
7d9bb753ff
@ -24,24 +24,31 @@ namespace UnityAtoms
|
||||
|
||||
public class BoolPreference : Preference<bool>
|
||||
{
|
||||
private bool? _cached = null;
|
||||
public override bool Get()
|
||||
{
|
||||
if (_cached != null) return _cached.Value;
|
||||
|
||||
if (!EditorPrefs.HasKey(Key))
|
||||
{
|
||||
EditorPrefs.SetBool(Key, DefaultValue);
|
||||
_cached = DefaultValue;
|
||||
return _cached.Value;
|
||||
}
|
||||
|
||||
return EditorPrefs.GetBool(Key);
|
||||
_cached = EditorPrefs.GetBool(Key);
|
||||
return _cached.Value;
|
||||
}
|
||||
|
||||
public override void Set(bool value)
|
||||
{
|
||||
_cached = value;
|
||||
EditorPrefs.SetBool(Key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsDebugModeEnabled { get => DEBUG_MODE_PREF.Get(); }
|
||||
|
||||
|
||||
private static BoolPreference DEBUG_MODE_PREF = new BoolPreference() { DefaultValue = false, Key = "UnityAtoms.DebugMode" };
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
|
@ -61,12 +61,12 @@ namespace UnityAtoms
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static StackTraceEntry Create(object obj, int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames), obj) : null;
|
||||
|
||||
|
||||
public static StackTraceEntry Create<T>(T obj, int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames), obj) : null;
|
||||
public static StackTraceEntry Create(int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames)) : null;
|
||||
|
||||
#else
|
||||
public static StackTraceEntry Create(object obj, int skipFrames = 0) => null;
|
||||
|
||||
public static StackTraceEntry Create<T>(T obj, int skipFrames = 0) => null;
|
||||
public static StackTraceEntry Create(int skipFrames = 0) => null;
|
||||
#endif
|
||||
|
||||
|
@ -11,6 +11,7 @@ namespace UnityAtoms
|
||||
|
||||
public static void AddStackTrace(int id, StackTraceEntry stackTrace)
|
||||
{
|
||||
if (stackTrace == null) return;
|
||||
if (AtomPreferences.IsDebugModeEnabled)
|
||||
{
|
||||
GetStackTraces(id).Insert(0, stackTrace);
|
||||
|
Loading…
Reference in New Issue
Block a user