bytes-array.sol

1.0.3 • Public • Published

BytesArray

Usage

Before

contract YourContract {
  // This is O(N^2) because of reallocations
  function yourFunction() returns (bytes memory result) {
    ...
    for (uint i = 0; i < N; i++) {
      ...
      // Reallocation
      result = abi.encodePacked(result, ...);
    }
  }
}

After

import "bytes-array.sol/BytesArray.sol";

contract YourContract {
  // This is O(N)
  using BytesArray for bytes[];

  function yourFunction() returns (bytes memory result) {
    ...
    bytes[] memory parts = new bytes[](N);
    for (uint i = 0; i < N; i++) {
      ...
      parts[i] = abi.encodePacked(...);
    }
    result = parts.packed();
  }
}

Readme

Keywords

Package Sidebar

Install

npm i bytes-array.sol

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

2.68 kB

Total Files

3

Last publish

Collaborators

  • snakajima