-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: get path and tuples on constructor #329
feat: get path and tuples on constructor #329
Conversation
src/codec.ts
Outdated
if (path == null) { | ||
path = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't get it. If value for path
is not set, we are resetting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check this implementation
Line 699 in 76fa6f5
if (this.#path == null) { |
when there is no path in any protocols, it means path = null
and we don't need to search for it again the next time getPath() is called
I'll add more comments to this function referring to DefaultMultiaddr.getPath()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, with ==
you are checking for both null
and `undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nazarhussain yeah it's a bit confused, I changed the condition to if (path === undefined)
instead
closing this PR as there are further improvement in #330 |
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`. --------- Co-authored-by: Tuyen Nguyen <[email protected]>
## [12.1.4](v12.1.3...v12.1.4) (2023-07-28) ### Bug Fixes * precalculate multiaddr parts ([#330](#330)) ([cf7e9c6](cf7e9c6)), closes [#329](#329) ### Trivial Changes * update project config ([#326](#326)) ([76fa6f5](76fa6f5)) ### Documentation * import from @multiformats/multiaddr ([#327](#327)) ([4dedd4b](4dedd4b)) ### Dependencies * bump multiformats from 11.0.2 to 12.0.1 ([#328](#328)) ([07d4f8a](07d4f8a)) * **dev:** bump aegir from 39.0.13 to 40.0.2 ([#333](#333)) ([3480741](3480741))
Motivation
MultiaddrInput
is a stringDescription
DefaultMultiaddr
whenMultiaddrInput
is a string, we already have tuples instringTuplesToTuples
, just need to return it