mirror of
https://github.com/typst/typst
synced 2025-05-19 11:35:27 +08:00
Small improvements 🧺
This commit is contained in:
parent
904bc392ab
commit
dc8d5d2f1e
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user