diff --git a/rlp.go b/rlp.go index 2ea8ff0942..2c04317aec 100644 --- a/rlp.go +++ b/rlp.go @@ -45,7 +45,7 @@ func Decode(data []byte, pos int) (interface{}, int) { slice := make([]interface{}, 0) switch { case char < 24: - return append(slice, data[pos]), pos + 1 + return data[pos], pos + 1 case char < 56: b := int(data[pos]) - 23 return FromBin(data[pos+1 : pos+1+b]), pos + 1 + b @@ -72,7 +72,7 @@ func Decode(data []byte, pos int) (interface{}, int) { return slice, pos case char < 192: b := int(data[pos]) - 183 - //b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref imprementation has an unused variable) + //b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref implementation has an unused variable) pos = pos+1+b for i := 0; i < b; i++ { var obj interface{} diff --git a/rlp_test.go b/rlp_test.go index c2d5ba263a..ae8dcced40 100644 --- a/rlp_test.go +++ b/rlp_test.go @@ -15,7 +15,6 @@ func TestEncode(t *testing.T) { dec,_ := Decode(bytes, 0) fmt.Printf("raw: %v encoded: %q == %v\n", dec, str, "dog") - sliceRes := "\x83CdogCgodCcat" strs := []string{"dog", "god", "cat"} bytes = Encode(strs) @@ -27,3 +26,10 @@ func TestEncode(t *testing.T) { dec,_ = Decode(bytes, 0) fmt.Printf("raw: %v encoded: %q == %v\n", dec, slice, strs) } + +func BenchmarkEncodeDecode(b *testing.B) { + for i := 0; i < b.N; i++ { + bytes := Encode([]string{"dog", "god", "cat"}) + Decode(bytes, 0) + } +}