From 33c663172bd472e043f0b453d2d45c50699ff628 Mon Sep 17 00:00:00 2001 From: The Depressed Milkman Date: Mon, 7 Nov 2022 20:14:46 +0100 Subject: Decrease number of heap allocations, and more Sent over the course of 2 diffs, no real functionality changes, but a couple general code improvements. The second email reads: > string encoding/decoding has been rewritten. The duplicate_elements() > function no longer allocates like crazy. The try_move() and do_move() > functions still need work, but have not been touched because they will > likely be rewritten shortly. --- src/encoded_string.rs | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/encoded_string.rs (limited to 'src/encoded_string.rs') diff --git a/src/encoded_string.rs b/src/encoded_string.rs deleted file mode 100644 index 55090a9..0000000 --- a/src/encoded_string.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::str; - -pub struct EncodedString<'a> { - pub s: str::Bytes<'a>, -} - -impl<'a> Iterator for EncodedString<'a> { - type Item = u8; - - fn next(&mut self) -> Option { - self.s.next().map(|c| match c { - b'\\' => match self.s.next() { - Some(b'n') => b'\n', - Some(b'\\') | None => b'\\', - Some(c) => c - }, - c => c - }) - } -} - -impl<'a> EncodedString<'a> { - pub fn decode(self) -> String { - String::from_utf8(self.s.collect()).unwrap() - } -} -- cgit v1.2.3