diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-02 20:22:08 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-02 20:22:08 +0200 |
| commit | dc8d5d2f1eadb19d0351fa214400d7ec7ba31a20 (patch) | |
| tree | 64c0ebb599c480270ac529edbc14b02534853828 /src/parse | |
| parent | 904bc392abdcd7c48fa4541594f6218168afb61f (diff) | |
Small improvements 🧺
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/parser.rs | 6 | ||||
| -rw-r--r-- | src/parse/resolve.rs | 4 | ||||
| -rw-r--r-- | src/parse/scanner.rs | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs index d34730c8..041a61bc 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -228,7 +228,7 @@ impl<'s> Parser<'s> { /// /// Returns `false` if there is no next token. pub fn check(&mut self, f: impl FnOnce(Token<'s>) -> bool) -> bool { - self.peek().map(f).unwrap_or(false) + self.peek().map_or(false, f) } /// Whether the end of the source string or group is reached. @@ -278,7 +278,9 @@ impl<'s> Parser<'s> { /// Set the position to the tokenizer's position and take the peeked token. fn bump(&mut self) -> Option<Token<'s>> { self.pos = self.tokens.pos(); - self.peeked.take() + let token = self.peeked; + self.peeked = None; + token } } diff --git a/src/parse/resolve.rs b/src/parse/resolve.rs index 1b289b1e..df5a5d41 100644 --- a/src/parse/resolve.rs +++ b/src/parse/resolve.rs @@ -89,12 +89,12 @@ fn trim_and_split_raw(raw: &str) -> (Vec<String>, bool) { let is_whitespace = |line: &String| line.chars().all(char::is_whitespace); // Trims a sequence of whitespace followed by a newline at the start. - if lines.first().map(is_whitespace).unwrap_or(false) { + if lines.first().map_or(false, is_whitespace) { lines.remove(0); } // Trims a newline followed by a sequence of whitespace at the end. - if lines.last().map(is_whitespace).unwrap_or(false) { + if lines.last().map_or(false, is_whitespace) { lines.pop(); } diff --git a/src/parse/scanner.rs b/src/parse/scanner.rs index b7107979..02562839 100644 --- a/src/parse/scanner.rs +++ b/src/parse/scanner.rs @@ -32,8 +32,6 @@ impl<'s> Scanner<'s> { /// Returns whether the char was consumed. pub fn eat_if(&mut self, c: char) -> bool { // Don't decode the char twice through peek() and eat(). - // - // TODO: Benchmark this vs. the naive version. if self.iter.next() == Some(c) { self.index += c.len_utf8(); true @@ -71,8 +69,6 @@ impl<'s> Scanner<'s> { if f(c) { // Undo the previous `next()` without peeking all the time // during iteration. - // - // TODO: Benchmark this vs. the naive peeking version. self.reset(); break; } |
