Browse Source

trie: avoid unnecessary slicing on shortnode decoding (#16917)

optimization code
Sarlor 7 years ago
parent
commit
ea06da0892
1 changed files with 3 additions and 4 deletions
  1. 3 4
      trie/encoding.go

+ 3 - 4
trie/encoding.go

@@ -53,10 +53,9 @@ func hexToCompact(hex []byte) []byte {
 
 func compactToHex(compact []byte) []byte {
 	base := keybytesToHex(compact)
-	base = base[:len(base)-1]
-	// apply terminator flag
-	if base[0] >= 2 {
-		base = append(base, 16)
+	// delete terminator flag
+	if base[0] < 2 {
+		base = base[:len(base)-1]
 	}
 	// apply odd flag
 	chop := 2 - base[0]&1