浏览代码

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

optimization code
Sarlor 7 年之前
父节点
当前提交
ea06da0892
共有 1 个文件被更改,包括 3 次插入4 次删除
  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