aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/common.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-08-14 22:08:49 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-08-14 22:08:49 +0800
commitf8d8b56b280dd921436fb046dbcaa010ef43122d (patch)
tree8e18333c06d7d6d80798d464e5ca81d029ca74ab /core/vm/common.go
parentd8aaa3a215ea19c0ccde2419832ac2bd80d8ddf0 (diff)
downloaddexon-f8d8b56b280dd921436fb046dbcaa010ef43122d.tar.gz
dexon-f8d8b56b280dd921436fb046dbcaa010ef43122d.tar.zst
dexon-f8d8b56b280dd921436fb046dbcaa010ef43122d.zip
core/vm: optimize copy-less data retrievals
Diffstat (limited to 'core/vm/common.go')
-rw-r--r--core/vm/common.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/core/vm/common.go b/core/vm/common.go
index 779cee006..17de38dec 100644
--- a/core/vm/common.go
+++ b/core/vm/common.go
@@ -34,7 +34,21 @@ func calcMemSize(off, l *big.Int) *big.Int {
// getData returns a slice from the data based on the start and size and pads
// up to size with zero's. This function is overflow safe.
-func getData(data []byte, start, size *big.Int) []byte {
+func getData(data []byte, start uint64, size uint64) []byte {
+ length := uint64(len(data))
+ if start > length {
+ start = length
+ }
+ end := start + size
+ if end > length {
+ end = length
+ }
+ return common.RightPadBytes(data[start:end], int(size))
+}
+
+// getDataBig returns a slice from the data based on the start and size and pads
+// up to size with zero's. This function is overflow safe.
+func getDataBig(data []byte, start *big.Int, size *big.Int) []byte {
dlen := big.NewInt(int64(len(data)))
s := math.BigMin(start, dlen)