From 73d3848797be013c069fb2c6fa77050e92bc17b2 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 15 Jul 2024 21:33:49 +0900 Subject: refactor: remove unnecessary mutability --- src/lib.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 90c3bab..3710e7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -244,11 +244,12 @@ impl Parser { match *next { b'}' => { - w.write_all(&mut ws)?; + w.write_all(&ws)?; return Ok(()); } b',' => { - w.write_all(&mut ws)?; + w.write_all(&ws)?; + // Re-use the memory buffer to avoid another allocation. ws.clear(); input.next(); @@ -264,19 +265,19 @@ impl Parser { match *c { b'}' => { self.repaired = true; - w.write_all(&mut ws)?; + w.write_all(&ws)?; return Ok(()); } _ => { w.write_all(b",")?; - w.write_all(&mut ws)?; + w.write_all(&ws)?; } } } _ => { self.repaired = true; w.write_all(b",")?; - w.write_all(&mut ws)?; + w.write_all(&ws)?; } } } @@ -366,11 +367,12 @@ impl Parser { match *next { b']' => { - w.write_all(&mut ws)?; + w.write_all(&ws)?; return Ok(()); } b',' => { - w.write_all(&mut ws)?; + w.write_all(&ws)?; + // Re-use the memory buffer to avoid another allocation. ws.clear(); input.next(); @@ -386,19 +388,19 @@ impl Parser { match *c { b']' => { self.repaired = true; - w.write_all(&mut ws)?; + w.write_all(&ws)?; return Ok(()); } _ => { w.write_all(b",")?; - w.write_all(&mut ws)?; + w.write_all(&ws)?; } } } _ => { self.repaired = true; w.write_all(b",")?; - w.write_all(&mut ws)?; + w.write_all(&ws)?; } } } -- cgit v1.2.3-70-g09d2