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

Commit 135b60e

Browse files
committed
inline StringSegment method expressions
1 parent 29fcad3 commit 135b60e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/ServiceStack.Text/Support/StringSegmentExtensions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ public static int IndexOfAny(this StringSegment value, char[] chars, int start,
4040
return index;
4141
}
4242

43+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
public static int IndexOfAny(this StringSegment value, char[] chars, int start) => value.IndexOfAny(chars, start, value.Length - start);
4445

46+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4547
public static string Substring(this StringSegment value, int pos) => value.Substring(pos, value.Length - pos);
4648

49+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4750
public static bool CompareIgnoreCase(this StringSegment value, string text) => value.Equals(text, StringComparison.OrdinalIgnoreCase);
4851

4952
public static StringSegment FromCsvField(this StringSegment text)
@@ -56,6 +59,7 @@ public static StringSegment FromCsvField(this StringSegment text)
5659
.Replace(CsvConfig.EscapedItemDelimiterString, CsvConfig.ItemDelimiterString));
5760
}
5861

62+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5963
public static bool ParseBoolean(this StringSegment value)
6064
{
6165
if (!value.TryParseBoolean(out bool result))
@@ -77,16 +81,19 @@ public static bool TryParseBoolean(this StringSegment value, out bool result)
7781
return value.CompareIgnoreCase(bool.FalseString);
7882
}
7983

84+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8085
public static bool TryParseDecimal(this StringSegment value, out decimal result)
8186
{
8287
return decimal.TryParse(value.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
8388
}
8489

90+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8591
public static bool TryParseFloat(this StringSegment value, out float result)
8692
{
8793
return float.TryParse(value.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
8894
}
8995

96+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9097
public static bool TryParseDouble(this StringSegment value, out double result)
9198
{
9299
return double.TryParse(value.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
@@ -144,56 +151,63 @@ private static string UnsignedMaxValueToIntType(ulong maxValue)
144151
}
145152
}
146153

154+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
147155
public static sbyte ParseSByte(this StringSegment value)
148156
{
149157
return JsConfig.UseSystemParseMethods
150158
? sbyte.Parse(value.Value, CultureInfo.InvariantCulture)
151159
: (sbyte)ParseSignedInteger(value, sbyte.MaxValue, sbyte.MinValue);
152160
}
153161

162+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
154163
public static byte ParseByte(this StringSegment value)
155164
{
156165
return JsConfig.UseSystemParseMethods
157166
? byte.Parse(value.Value, CultureInfo.InvariantCulture)
158167
: (byte)ParseUnsignedInteger(value, byte.MaxValue);
159168
}
160169

170+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
161171
public static short ParseInt16(this StringSegment value)
162172
{
163173
return JsConfig.UseSystemParseMethods
164174
? short.Parse(value.Value, CultureInfo.InvariantCulture)
165175
: (short)ParseSignedInteger(value, short.MaxValue, short.MinValue);
166176
}
167177

178+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168179
public static ushort ParseUInt16(this StringSegment value)
169180
{
170181
return JsConfig.UseSystemParseMethods
171182
? ushort.Parse(value.Value, CultureInfo.InvariantCulture)
172183
: (ushort)ParseUnsignedInteger(value, ushort.MaxValue);
173184
}
174185

175-
186+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
176187
public static int ParseInt32(this StringSegment value)
177188
{
178189
return JsConfig.UseSystemParseMethods
179190
? int.Parse(value.Value, CultureInfo.InvariantCulture)
180191
: (int)ParseSignedInteger(value, Int32.MaxValue, Int32.MinValue);
181192
}
182193

194+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
183195
public static uint ParseUInt32(this StringSegment value)
184196
{
185197
return JsConfig.UseSystemParseMethods
186198
? uint.Parse(value.Value, CultureInfo.InvariantCulture)
187199
: (uint)ParseUnsignedInteger(value, UInt32.MaxValue);
188200
}
189201

202+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
190203
public static long ParseInt64(this StringSegment value)
191204
{
192205
return JsConfig.UseSystemParseMethods
193206
? long.Parse(value.Value, CultureInfo.InvariantCulture)
194207
: ParseSignedInteger(value, Int64.MaxValue, Int64.MinValue);
195208
}
196209

210+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
197211
public static ulong ParseUInt64(this StringSegment value)
198212
{
199213
return JsConfig.UseSystemParseMethods

0 commit comments

Comments
 (0)