-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Avoid some format! into immediate format! #2913
Closed
Conversation
This file contains 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
alice-i-cecile
added
C-Code-Quality
A section of code that is hard to understand or change
S-Needs-Review
and removed
S-Needs-Triage
This issue needs to be labelled
labels
Oct 3, 2021
alice-i-cecile
approved these changes
Oct 3, 2021
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.
It all checks out. Thanks!
bjorn3
reviewed
Oct 3, 2021
bjorn3
reviewed
Oct 3, 2021
Testing alignment for
|
NiklasEi
approved these changes
Oct 4, 2021
IceSentry
approved these changes
Oct 4, 2021
alice-i-cecile
added
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
and removed
S-Needs-Review
labels
Oct 4, 2021
mockersf
approved these changes
Oct 4, 2021
bjorn3
approved these changes
Oct 5, 2021
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Oct 6, 2021
# Objective - Avoid usages of `format!` that ~immediately get passed to another `format!`. This avoids a temporary allocation and is just generally cleaner. ## Solution - `bevy_derive::shader_defs` does a `format!("{}", val.to_string())`, which is better written as just `format!("{}", val)` - `bevy_diagnostic::log_diagnostics_plugin` does a `format!("{:>}", format!(...))`, which is better written as `format!("{:>}", format_args!(...))` - `bevy_ecs::schedule` does `tracing::info!(..., name = &*format!("{:?}", val))`, which is better written with the tracing shorthand `tracing::info!(..., name = ?val)` - `bevy_reflect::reflect` does `f.write_str(&format!(...))`, which is better written as `write!(f, ...)` (this could also be written using `f.debug_tuple`, but I opted to maintain alt debug behavior) - `bevy_reflect::serde::{ser, de}` do `serde::Error::custom(format!(...))`, which is better written as `Error::custom(format_args!(...))`, as `Error::custom` takes `impl Display` and just immediately calls `format!` again
bors
bot
changed the title
Avoid some format! into immediate format!
[Merged by Bors] - Avoid some format! into immediate format!
Oct 6, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-Code-Quality
A section of code that is hard to understand or change
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
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.
Objective
format!
that ~immediately get passed to anotherformat!
. This avoids a temporary allocation and is just generally cleaner.Solution
bevy_derive::shader_defs
does aformat!("{}", val.to_string())
, which is better written as justformat!("{}", val)
bevy_diagnostic::log_diagnostics_plugin
does aformat!("{:>}", format!(...))
, which is better written asformat!("{:>}", format_args!(...))
bevy_ecs::schedule
doestracing::info!(..., name = &*format!("{:?}", val))
, which is better written with the tracing shorthandtracing::info!(..., name = ?val)
bevy_reflect::reflect
doesf.write_str(&format!(...))
, which is better written aswrite!(f, ...)
(this could also be written usingf.debug_tuple
, but I opted to maintain alt debug behavior)bevy_reflect::serde::{ser, de}
doserde::Error::custom(format!(...))
, which is better written asError::custom(format_args!(...))
, asError::custom
takesimpl Display
and just immediately callsformat!
again