summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-02 20:22:08 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-02 20:22:08 +0200
commitdc8d5d2f1eadb19d0351fa214400d7ec7ba31a20 (patch)
tree64c0ebb599c480270ac529edbc14b02534853828 /src
parent904bc392abdcd7c48fa4541594f6218168afb61f (diff)
Small improvements 🧺
Diffstat (limited to 'src')
-rw-r--r--src/library/align.rs2
-rw-r--r--src/parse/parser.rs6
-rw-r--r--src/parse/resolve.rs4
-rw-r--r--src/parse/scanner.rs4
4 files changed, 7 insertions, 9 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
index 350724f7..d36108a4 100644
--- a/src/library/align.rs
+++ b/src/library/align.rs
@@ -35,7 +35,7 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass
// if the alignment is `center` for a positional argument. Then we set
// `deferred_center` to true and handle the situation once we know more.
if let Some(axis) = axis {
- if align.v.axis().map(|a| a != axis).unwrap_or(false) {
+ if align.v.axis().map_or(false, |a| a != axis) {
error!(
@f, align.span,
"invalid alignment {} for {} axis", align.v, axis,
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;
}