From dc3a217b2ff73fe53669e62e7a67474f9a09ef88 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 23 Apr 2021 23:37:33 +0800 Subject: [PATCH] ImmutableString += String optimized. --- src/utils.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 98e381c5..234ad303 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -395,7 +395,13 @@ impl Add for &ImmutableString { impl AddAssign for ImmutableString { #[inline(always)] fn add_assign(&mut self, rhs: String) { - self.make_mut().push_str(&rhs); + if !rhs.is_empty() { + if self.is_empty() { + self.0 = Into::::into(rhs).into(); + } else { + self.make_mut().push_str(&rhs); + } + } } }