use in built bytes clone method

This commit is contained in:
Sahil-4555 2025-12-01 11:18:50 +05:30
parent 6f2cbb7a27
commit 4ee67b8d25

View file

@ -18,6 +18,7 @@
package common package common
import ( import (
"bytes"
"encoding/hex" "encoding/hex"
"errors" "errors"
@ -37,14 +38,8 @@ func FromHex(s string) []byte {
} }
// CopyBytes returns an exact copy of the provided bytes. // CopyBytes returns an exact copy of the provided bytes.
func CopyBytes(b []byte) (copiedBytes []byte) { func CopyBytes(b []byte) []byte {
if b == nil { return bytes.Clone(b)
return nil
}
copiedBytes = make([]byte, len(b))
copy(copiedBytes, b)
return
} }
// has0xPrefix validates str begins with '0x' or '0X'. // has0xPrefix validates str begins with '0x' or '0X'.