Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 724c7da

Browse files
committed
Add method inlining on short methods
1 parent 935034c commit 724c7da

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/ServiceStack.Text/Json/JsonUtils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public static void WriteString(TextWriter writer, string value)
111111
writer.Write(QuoteChar);
112112
}
113113

114+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114115
private static bool IsPrintable(this char c)
115116
{
116117
return c >= 32 && c <= 126;
@@ -128,6 +129,7 @@ private static bool IsPrintable(this char c)
128129
/// TODO: Possible Linq-only solution requires profiling: return value.Any(c => !c.IsPrintable() || c == QuoteChar || c == EscapeChar);
129130
/// </remarks>
130131
private static bool HasAnyEscapeChars(string value)
132+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
131133
{
132134
var len = value.Length;
133135
for (var i = 0; i < len; i++)
@@ -142,6 +144,7 @@ private static bool HasAnyEscapeChars(string value)
142144
}
143145

144146
// Micro optimized
147+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
145148
public static void IntToHex(int intValue, char[] hex)
146149
{
147150
// TODO: test if unrolling loop is faster
@@ -157,13 +160,15 @@ public static void IntToHex(int intValue, char[] hex)
157160
}
158161
}
159162

163+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
160164
public static bool IsJsObject(string value)
161165
{
162166
return !string.IsNullOrEmpty(value)
163167
&& value[0] == '{'
164168
&& value[value.Length - 1] == '}';
165169
}
166170

171+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
167172
public static bool IsJsArray(string value)
168173
{
169174
return !string.IsNullOrEmpty(value)

0 commit comments

Comments
 (0)