Skip to content

Commit 1594596

Browse files
committed
nit: improve TextInfo Add|SubAssign impls
1 parent 0679f9b commit 1594596

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/tree/text_info.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ impl Add for TextInfo {
4949
impl AddAssign for TextInfo {
5050
#[inline]
5151
fn add_assign(&mut self, other: TextInfo) {
52-
*self = *self + other;
52+
let Self {
53+
bytes,
54+
chars,
55+
utf16_surrogates,
56+
line_breaks,
57+
} = self;
58+
*bytes += other.bytes;
59+
*chars += other.chars;
60+
*utf16_surrogates += other.utf16_surrogates;
61+
*line_breaks += other.line_breaks;
5362
}
5463
}
5564

@@ -69,6 +78,15 @@ impl Sub for TextInfo {
6978
impl SubAssign for TextInfo {
7079
#[inline]
7180
fn sub_assign(&mut self, other: TextInfo) {
72-
*self = *self - other;
81+
let Self {
82+
bytes,
83+
chars,
84+
utf16_surrogates,
85+
line_breaks,
86+
} = self;
87+
*bytes -= other.bytes;
88+
*chars -= other.chars;
89+
*utf16_surrogates -= other.utf16_surrogates;
90+
*line_breaks -= other.line_breaks;
7391
}
7492
}

0 commit comments

Comments
 (0)