Removed slice appending for integers

pull/2/head
obscuren 11 years ago
parent d6460f3de1
commit 5a7eae705b
  1. 4
      rlp.go
  2. 8
      rlp_test.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{}

@ -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)
}
}

Loading…
Cancel
Save