From b676f7114ad864f7f68a3d36462b8479f640caf8 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Wed, 21 Aug 2024 10:06:08 +0900 Subject: [PATCH 1/2] Optimized KeyConverters --- src/Libplanet.Action/State/KeyConverters.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Libplanet.Action/State/KeyConverters.cs b/src/Libplanet.Action/State/KeyConverters.cs index a43b0ae0681..cb5886de813 100644 --- a/src/Libplanet.Action/State/KeyConverters.cs +++ b/src/Libplanet.Action/State/KeyConverters.cs @@ -1,3 +1,5 @@ +using System.Collections.Immutable; +using System.Runtime.CompilerServices; using Libplanet.Crypto; using Libplanet.Store.Trie; using Libplanet.Types.Assets; @@ -43,7 +45,7 @@ public static KeyBytes ToStateKey(Address address) buffer[i * 2 + 1] = _conversionTable[addressBytes[i] & 0xf]; } - return new KeyBytes(buffer); + return new KeyBytes(Unsafe.As>(ref buffer)); } // $"_{ByteUtil.Hex(address.ByteArray)}_{ByteUtil.Hex(currency.Hash.ByteArray)}" @@ -68,7 +70,7 @@ public static KeyBytes ToFungibleAssetKey(Address address, Currency currency) buffer[offset + 2 + i * 2 + 1] = _conversionTable[currencyBytes[i] & 0xf]; } - return new KeyBytes(buffer); + return new KeyBytes(Unsafe.As>(ref buffer)); } public static KeyBytes ToFungibleAssetKey( @@ -90,7 +92,7 @@ public static KeyBytes ToTotalSupplyKey(Currency currency) buffer[2 + i * 2 + 1] = _conversionTable[currencyBytes[i] & 0xf]; } - return new KeyBytes(buffer); + return new KeyBytes(Unsafe.As>(ref buffer)); } } } From 2acd3954ac4eaae53ebd0a5d6c3e0ff2e453c51d Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Wed, 21 Aug 2024 10:10:32 +0900 Subject: [PATCH 2/2] Changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 69ef465c94c..a6d8f0d5947 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,6 +32,7 @@ To be released. `BlockHash` in a given `BlockLocator`. [[#3913]] - (Libplanet.Store) Optimized `HashNode.ToBencodex()` method. [[#3922], [#3924]] + - (Libplanet.Store) Optimized internal conversions to `KeyBytes`. [[#3926]] ### Bug fixes @@ -42,6 +43,7 @@ To be released. [#3913]: https://github.com/planetarium/libplanet/pull/3913 [#3922]: https://github.com/planetarium/libplanet/issues/3922 [#3924]: https://github.com/planetarium/libplanet/pull/3924 +[#3926]: https://github.com/planetarium/libplanet/pull/3926 Version 5.2.2