Skip to content

Commit 3ca31cc

Browse files
committed
perf: span changes to EmoteUtilities
1 parent 4d3f472 commit 3ca31cc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Discord.Net/Utilities/EmoteUtilities.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ public static bool TryParseGuildEmote(ReadOnlySpan<char> formatted, out (ulong,
2424
{
2525
result = default;
2626

27-
if (formatted.IndexOf('<') != 0 || formatted.IndexOf(':') != 1 || formatted.IndexOf('>') != formatted.Length - 1)
27+
if (formatted.Length < 3)
28+
return false;
29+
if (formatted[0] != '<' || formatted[1] != ':' || formatted[formatted.Length-1] != '>')
2830
return false;
2931

3032
int closingIndex = formatted.LastIndexOf(':');
31-
if (closingIndex < 0)
33+
if (closingIndex < 2)
3234
return false;
3335

3436
ReadOnlySpan<char> name = formatted.Slice(2, closingIndex-2);
3537
ReadOnlySpan<char> idStr = formatted.Slice(closingIndex + 1, formatted.Length - (name.Length + 4));
36-
idStr = idStr.Slice(0, idStr.Length - 1); // ignore closing >
3738

3839
if (!ulong.TryParse(idStr.ToString(), out ulong id))
3940
return false;

0 commit comments

Comments
 (0)