aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-28 09:24:01 +0800
committerobscuren <obscuren@obscura.com>2013-12-28 09:24:01 +0800
commit5a7eae705b83d75cb780279e386f183c4b6e19c6 (patch)
tree132efdfe17e3af1faa628a84768d3e635d40f355
parentd6460f3de171f018860ea9c3f4a69536c8ef82ac (diff)
downloadgo-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar.gz
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar.bz2
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar.lz
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar.xz
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.tar.zst
go-tangerine-5a7eae705b83d75cb780279e386f183c4b6e19c6.zip
Removed slice appending for integers
-rw-r--r--rlp.go4
-rw-r--r--rlp_test.go8
2 files changed, 9 insertions, 3 deletions
diff --git a/rlp.go b/rlp.go
index 2ea8ff094..2c04317ae 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 c2d5ba263..ae8dcced4 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)
+ }
+}