This repository was archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 653
refactor(rome_formatter): Return reference from context.comments()
#3120
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!bench_formatter |
Deploying with
|
Latest commit: |
e1cd151
|
Status: | ✅ Deploy successful! |
Preview URL: | https://f12541df.tools-8rn.pages.dev |
Branch Preview URL: | https://refactor-comments-internal-r.tools-8rn.pages.dev |
Formatter Benchmark Results
|
`context.comments` used to return a `Rc<Comments>` so that the lifetime of `comments` isn't bound to the lifetime of the `FormatContext`. This is necessary to support writing to the formatter while holding to a reference of comments: (Pseudo code): ```rust let comments = f.context().comments(); for comment in comments.leading_comments(node) { write!(f, [comment])?; } ``` The downside of returning an `Rc` is that every code path using `comments` pays for the overhead of incrementing the `Rc` counter. This PR changes `Comments` to use an `Rc` internally to enable cheap cloning, similar to how `SyntaxNode` works. This allows `context.comments()` to return a reference to `Comments` instead and only code paths that need to write to the formatter have to pay the overhead of cloning the comments. ## Tests `cargo test` as this PR isn't adding any new functionality
8e32a0c
to
de7cb04
Compare
ematipico
approved these changes
Aug 29, 2022
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
context.comments
used to return aRc<Comments>
so that the lifetime ofcomments
isn't bound to the lifetime of theFormatContext
. This is necessary to support writing to the formatter while holding to a reference of comments:(Pseudo code):
The downside of returning an
Rc
is that every code path usingcomments
pays for the overhead of incrementing theRc
counter and using anRc
in the signature leaks the abstraction.This PR changes
Comments
to use anRc
internally to enable cheap cloning, similar to howSyntaxNode
works. This allowscontext.comments()
to return a reference toComments
instead and only code paths that need to write to the formatter have to pay the overhead of cloning the comments.Tests
cargo test
as this PR isn't adding any new functionality