Skip to content

Commit 989fb62

Browse files
hrxidavidbarsky
andauthored
core: avoid unnecessary format_args! and write! macros (#1988)
This branch removes some unnecessary uses of the `format_args!` and `write!` macros in `tracing-core`. Using `fmt::Display::fmt` and similar rather than the macros may be slightly more efficient. Co-authored-by: David Barsky <[email protected]>
1 parent b16dc03 commit 989fb62

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tracing-core/src/field.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub trait Visit {
214214
#[cfg(feature = "std")]
215215
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
216216
fn record_error(&mut self, field: &Field, value: &(dyn std::error::Error + 'static)) {
217-
self.record_debug(field, &format_args!("{}", value))
217+
self.record_debug(field, &DisplayValue(value))
218218
}
219219

220220
/// Visit a value implementing `fmt::Debug`.
@@ -499,19 +499,19 @@ where
499499
T: fmt::Display,
500500
{
501501
fn record(&self, key: &Field, visitor: &mut dyn Visit) {
502-
visitor.record_debug(key, &format_args!("{}", self.0))
502+
visitor.record_debug(key, self)
503503
}
504504
}
505505

506506
impl<T: fmt::Display> fmt::Debug for DisplayValue<T> {
507507
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
508-
write!(f, "{}", self.0)
508+
fmt::Display::fmt(self, f)
509509
}
510510
}
511511

512512
impl<T: fmt::Display> fmt::Display for DisplayValue<T> {
513513
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
514-
fmt::Display::fmt(&self.0, f)
514+
self.0.fmt(f)
515515
}
516516
}
517517

@@ -530,7 +530,7 @@ where
530530

531531
impl<T: fmt::Debug> fmt::Debug for DebugValue<T> {
532532
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
533-
write!(f, "{:?}", self.0)
533+
self.0.fmt(f)
534534
}
535535
}
536536

0 commit comments

Comments
 (0)