Browse Source

copy over loop

obscuren 10 năm trước cách đây
mục cha
commit
62236dd95e
2 tập tin đã thay đổi với 4 bổ sung14 xóa
  1. 2 9
      common/types.go
  2. 2 5
      core/types/common.go

+ 2 - 9
common/types.go

@@ -35,10 +35,7 @@ func (h *Hash) SetBytes(b []byte) {
 		b = b[len(b)-hashLength:]
 	}
 
-	// reverse loop
-	for i := len(b) - 1; i >= 0; i-- {
-		h[hashLength-len(b)+i] = b[i]
-	}
+	copy(h[hashLength-len(b):], b)
 }
 
 // Set string `s` to h. If s is larger than len(h) it will panic
@@ -73,11 +70,7 @@ func (a *Address) SetBytes(b []byte) {
 	if len(b) > len(a) {
 		b = b[len(b)-addressLength:]
 	}
-
-	// reverse loop
-	for i := len(b) - 1; i >= 0; i-- {
-		a[addressLength-len(b)+i] = b[i]
-	}
+	copy(a[addressLength-len(b):], b)
 }
 
 // Set string `s` to a. If s is larger than len(a) it will panic

+ 2 - 5
core/types/common.go

@@ -3,8 +3,8 @@ package types
 import (
 	"math/big"
 
-	"github.com/ethereum/go-ethereum/state"
 	"github.com/ethereum/go-ethereum/common"
+	"github.com/ethereum/go-ethereum/state"
 
 	"fmt"
 )
@@ -28,10 +28,7 @@ func (b *Bloom) SetBytes(d []byte) {
 		panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d)))
 	}
 
-	// reverse loop
-	for i := len(d) - 1; i >= 0; i-- {
-		b[bloomLength-len(d)+i] = b[i]
-	}
+	copy(b[bloomLength-len(d):], d)
 }
 
 func (b Bloom) Big() *big.Int {