Skip to content

Commit 17d370a

Browse files
authored
Remove usage of Linq in Base62 encoding
Should be faster and cause fewer allocations
1 parent ef4f5ef commit 17d370a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

System/Base62.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#endregion
2525

2626
#nullable enable
27-
using System.Linq;
2827
using System.Numerics;
2928
using System.Text;
3029

@@ -53,7 +52,11 @@ public static string Encode(BigInteger value)
5352
value /= 62;
5453
}
5554

56-
return new string(sb.ToString().Reverse().ToArray());
55+
// Reverse the string, since we're building it backwards,
56+
var chars = sb.ToString().ToCharArray();
57+
Array.Reverse(chars);
58+
59+
return new string(chars);
5760
}
5861

5962
/// <summary>
@@ -78,4 +81,4 @@ public static BigInteger Decode(string value)
7881
_ => throw new ArgumentException($"Cannot decode char '{c}' from base 62.", nameof(c)),
7982
};
8083
}
81-
}
84+
}

0 commit comments

Comments
 (0)