multiformats / js-multiaddr

JavaScript implementation of multiaddr
http://multiformats.github.io/js-multiaddr
Other
109 stars 64 forks source link

fix: precalculate multiaddr parts #330

Closed wemeetagain closed 1 year ago

wemeetagain commented 1 year ago

Taking #329 to its logical extreme, we're able to simplify the codebase (mostly codec.ts and its interaction with DefaultMultiaddr).

Precalculate a MultiaddrParts when constructing a DefaultMultiaddr. MultiaddrParts is essentially an object containing all data which is stored in a DefaultMultiaddr.

This makes all DefaultMultiaddr methods cheap, at the expense of always storing the string, bytes, tuples, stringTuples, and path of the multiaddr.

The two important functions to review are stringToMultiaddrParts and bytesToMultiaddrParts, which convert untrusted string and bytes into MultiaddrParts.

cc @tuyennhv

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 12.1.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: