diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-06-24 00:03:49 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-06-26 07:19:08 +0800 |
commit | 5127cbb22c8be536996137416f826afd231b0c14 (patch) | |
tree | fd82c694e390473f76d9aa37f6c3bba3ddbcc224 /packages/contracts/src | |
parent | 9175b43542a8797b0eb3c24e8188ebac67242733 (diff) | |
download | dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar.gz dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar.bz2 dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar.lz dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar.xz dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.tar.zst dexon-sol-tools-5127cbb22c8be536996137416f826afd231b0c14.zip |
Return inplace bytes in LibBytes.readBytesWithLength
Diffstat (limited to 'packages/contracts/src')
-rw-r--r-- | packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index e4cbf318b..289d086d6 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -459,6 +459,8 @@ library LibBytes { } /// @dev Reads nested bytes from a specific position. + /// @dev NOTE: the returned value overlaps with the input value. + /// Both should be treated as immutable. /// @param b Byte array containing nested bytes. /// @param index Index of nested bytes. /// @return result Nested bytes. @@ -480,15 +482,11 @@ library LibBytes { b.length >= index + nestedBytesLength, GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED ); - - // Allocate memory and copy value to result - result = new bytes(nestedBytesLength); - memCopy( - result.contentAddress(), - b.contentAddress() + index, - nestedBytesLength - ); - + + // Return a pointer to the byte array as it exists inside `b` + assembly { + result := add(b, index) + } return result; } |