Skip to content

Commit a7efdcb

Browse files
realleseefjl
andauthored
p2p/rlpx: optimize XOR operation using bitutil.XORBytes (ethereum#32217)
Replace manual byte-by-byte XOR implementation with the optimized bitutil.XORBytes function. This improves performance by using word-sized operations on supported architectures while maintaining the same functionality. The optimized version processes data in bulk rather than one byte at a time --------- Co-authored-by: Felix Lange <[email protected]>
1 parent 264c06a commit a7efdcb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

p2p/rlpx/rlpx.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"net"
3434
"time"
3535

36+
"github.com/ethereum/go-ethereum/common/bitutil"
3637
"github.com/ethereum/go-ethereum/crypto"
3738
"github.com/ethereum/go-ethereum/crypto/ecies"
3839
"github.com/ethereum/go-ethereum/rlp"
@@ -676,8 +677,6 @@ func exportPubkey(pub *ecies.PublicKey) []byte {
676677

677678
func xor(one, other []byte) (xor []byte) {
678679
xor = make([]byte, len(one))
679-
for i := 0; i < len(one); i++ {
680-
xor[i] = one[i] ^ other[i]
681-
}
680+
bitutil.XORBytes(xor, one, other)
682681
return xor
683682
}

0 commit comments

Comments
 (0)