mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-27 13:01:37 +00:00
use less intermediate formatting (-5% improvement)
This commit is contained in:
parent
b9241c0666
commit
64e082a5f8
@ -532,7 +532,8 @@ impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz> {
|
||||
|
||||
impl<Tz: TimeZone> fmt::Debug for Date<Tz> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}{:?}", self.naive_local(), self.offset)
|
||||
self.naive_local().fmt(f)?;
|
||||
self.offset.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,7 +542,8 @@ where
|
||||
Tz::Offset: fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.naive_local(), self.offset)
|
||||
self.naive_local().fmt(f)?;
|
||||
self.offset.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ use alloc::string::{String, ToString};
|
||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt::Write;
|
||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use core::{fmt, hash, str};
|
||||
#[cfg(feature = "std")]
|
||||
@ -990,7 +991,8 @@ impl<Tz: TimeZone> Sub<Days> for DateTime<Tz> {
|
||||
|
||||
impl<Tz: TimeZone> fmt::Debug for DateTime<Tz> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}{:?}", self.naive_local(), self.offset)
|
||||
self.naive_local().fmt(f)?;
|
||||
self.offset.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -999,7 +1001,9 @@ where
|
||||
Tz::Offset: fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} {}", self.naive_local(), self.offset)
|
||||
self.naive_local().fmt(f)?;
|
||||
f.write_char(' ')?;
|
||||
self.offset.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -737,7 +737,7 @@ fn format_inner<'a>(
|
||||
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
|
||||
// reuse `Debug` impls which already print ISO 8601 format.
|
||||
// this is faster in this way.
|
||||
write!(result, "{:?}T{:?}", d, t)?;
|
||||
write!(result, "{:?}", crate::NaiveDateTime::new(*d, *t))?;
|
||||
Some(write_local_minus_utc(result, off, false, Colons::Single))
|
||||
} else {
|
||||
None
|
||||
|
@ -6,6 +6,7 @@
|
||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||
use core::borrow::Borrow;
|
||||
use core::convert::TryFrom;
|
||||
use core::fmt::Write;
|
||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use core::{fmt, str};
|
||||
|
||||
@ -1629,7 +1630,9 @@ impl Sub<Days> for NaiveDateTime {
|
||||
/// ```
|
||||
impl fmt::Debug for NaiveDateTime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}T{:?}", self.date, self.time)
|
||||
self.date.fmt(f)?;
|
||||
f.write_char('T')?;
|
||||
self.time.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1660,7 +1663,9 @@ impl fmt::Debug for NaiveDateTime {
|
||||
/// ```
|
||||
impl fmt::Display for NaiveDateTime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} {}", self.date, self.time)
|
||||
self.date.fmt(f)?;
|
||||
f.write_char(' ')?;
|
||||
self.time.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user