Merge pull request #1043 from obscuren/test_fixes

core/vm: optimisation on RETURN and updated tests
This commit is contained in:
Jeffrey Wilcke
2015-05-20 03:06:04 -07:00
3 changed files with 35 additions and 13 deletions

View File

@ -49,6 +49,18 @@ func (self *Memory) Get(offset, size int64) (cpy []byte) {
return
}
func (self *Memory) GetPtr(offset, size int64) []byte {
if size == 0 {
return nil
}
if len(self.store) > int(offset) {
return self.store[offset : offset+size]
}
return nil
}
func (m *Memory) Len() int {
return len(m.store)
}

View File

@ -695,7 +695,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
self.Printf("resume %x (%v)", context.Address(), context.Gas)
case RETURN:
offset, size := stack.pop(), stack.pop()
ret := mem.Get(offset.Int64(), size.Int64())
ret := mem.GetPtr(offset.Int64(), size.Int64())
self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl()