Skip to content

Commit 69511a3

Browse files
author
David Kline
authored
Merge pull request #10369 from keveleigh/remove-allocs
[2.7.3] Update strings to const and cache type to reduce allocs
2 parents 7799f8f + 74b398e commit 69511a3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Assets/MRTK/Core/Services/BaseService.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public abstract class BaseService : IMixedRealityService, IMixedRealityServiceSt
1313
{
1414
public const uint DefaultPriority = 10;
1515

16+
public BaseService()
17+
{
18+
typeName = new[] { GetType().ToString() };
19+
}
20+
1621
#region IMixedRealityService Implementation
1722

1823
/// <inheritdoc />
@@ -68,12 +73,18 @@ public virtual void Destroy()
6873

6974
private bool? isInitialized = null;
7075

76+
private readonly string[] typeName = null;
77+
78+
private const string IsInitializedAssert = "{0} has not set a value for IsInitialized; returning false.";
79+
private const string IsEnabledAssert = "{0} has not set a value for IsEnabled; returning false.";
80+
private const string IsMarkedDestroyedAssert = "{0} has not set a value for IsMarkedDestroyed; returning false.";
81+
7182
/// <inheritdoc />
7283
public virtual bool IsInitialized
7384
{
7485
get
7586
{
76-
Debug.Assert(isInitialized.HasValue, $"{GetType()} has not set a value for IsInitialized, returning false.");
87+
Debug.AssertFormat(isInitialized.HasValue, IsInitializedAssert, typeName);
7788
return isInitialized ?? false;
7889
}
7990

@@ -87,7 +98,7 @@ public virtual bool IsEnabled
8798
{
8899
get
89100
{
90-
Debug.Assert(isEnabled.HasValue, $"{GetType()} has not set a value for IsEnabled, returning false.");
101+
Debug.AssertFormat(isEnabled.HasValue, IsEnabledAssert, typeName);
91102
return isEnabled ?? false;
92103
}
93104

@@ -101,7 +112,7 @@ public virtual bool IsMarkedDestroyed
101112
{
102113
get
103114
{
104-
Debug.Assert(isMarkedDestroyed.HasValue, $"{GetType()} has not set a value for IsMarkedDestroyed, returning false.");
115+
Debug.AssertFormat(isMarkedDestroyed.HasValue, IsMarkedDestroyedAssert, typeName);
105116
return isMarkedDestroyed ?? false;
106117
}
107118

0 commit comments

Comments
 (0)