Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 62f170c

Browse files
committed
Optimized truncation
1 parent 6942f39 commit 62f170c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ethcore/src/evm/interpreter/memory.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ impl Memory for Vec<u8> {
116116
}
117117

118118
fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData {
119-
let offset = offset.low_u64() as usize;
119+
let mut offset = offset.low_u64() as usize;
120120
let size = size.low_u64() as usize;
121121
if !is_valid_range(offset, size) {
122122
return ReturnData::empty()
123123
}
124124
if self.len() - size > MAX_RETURN_WASTE_BYTES {
125-
let mem = self.drain(offset..).take(size).collect();
126-
ReturnData::new(mem, 0, size)
127-
} else {
128-
ReturnData::new(self, offset, size)
125+
{ let _ = self.drain(..offset); }
126+
self.truncate(size);
127+
self.shrink_to_fit();
128+
offset = 0;
129129
}
130+
ReturnData::new(self, offset, size)
130131
}
131132
}
132133

0 commit comments

Comments
 (0)