[#20] Client: Optimize memory usage
Avoid memory allocation, use cache and static Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
35fe791406
commit
0ddde467cd
46 changed files with 596 additions and 372 deletions
|
@ -51,13 +51,13 @@ public static class Base58
|
|||
int digit = Alphabet.IndexOf(input[i]);
|
||||
if (digit < 0)
|
||||
throw new FormatException($"Invalid Base58 character '{input[i]}' at position {i}");
|
||||
|
||||
|
||||
bi = bi * Alphabet.Length + digit;
|
||||
}
|
||||
|
||||
int leadingZeroCount = input.TakeWhile(c => c == Alphabet[0]).Count();
|
||||
var leadingZeros = new byte[leadingZeroCount];
|
||||
|
||||
|
||||
if (bi.IsZero)
|
||||
return leadingZeros;
|
||||
|
||||
|
@ -65,9 +65,9 @@ public static class Base58
|
|||
|
||||
var firstNonZeroIndex = 0;
|
||||
|
||||
while(bytesBigEndian.ElementAt(firstNonZeroIndex) == 0x0)
|
||||
while (bytesBigEndian.ElementAt(firstNonZeroIndex) == 0x0)
|
||||
firstNonZeroIndex++;
|
||||
|
||||
|
||||
var bytesWithoutLeadingZeros = bytesBigEndian.Skip(firstNonZeroIndex).ToArray();
|
||||
|
||||
return ArrayHelper.Concat(leadingZeros, bytesWithoutLeadingZeros);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue