1.0.3 • Published 1 year ago

bytes-array.sol v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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();
  }
}
1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago