Skip to content

Commit

Permalink
fix: unnecessary array copy when pack encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>
  • Loading branch information
mpetrunic committed Oct 25, 2023
1 parent f860b04 commit 9606f73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/web3-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,8 @@ Documentation:
- Fix issue with default config with babel (and React): "TypeError: Cannot convert a BigInt value to a number #6187" (#6506)
- Fixed bug in chunks processing logic (#6496)

## [Unreleased]
## [Unreleased]

### Fixed

- Fix unecessary array copy when pack encoding
5 changes: 4 additions & 1 deletion packages/web3-utils/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ export const processSolidityEncodePackedArgs = (arg: Sha3Input): string => {
* Encode packed arguments to a hexstring
*/
export const encodePacked = (...values: Sha3Input[]): string => {
const args = Array.prototype.slice.call(values);
let args = values;
if(!Array.isArray(values)) {
args = [values]
}
const hexArgs = args.map(processSolidityEncodePackedArgs);
return `0x${hexArgs.join('').toLowerCase()}`;
};
Expand Down

0 comments on commit 9606f73

Please sign in to comment.