fast linked list thing
This commit is contained in:
parent
c937707865
commit
209123de3a
2 changed files with 25 additions and 18 deletions
|
@ -113,28 +113,29 @@ impl Iterator for SExpIterator {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
loop {
|
loop {
|
||||||
match (self.elements.pop_front(), self.elements.pop_front()) {
|
let first_is_kw = self.elements.front().map_or(false, |x| x.1.is_keyword());
|
||||||
(Some(Sp(kw_l, Expr::Keyword(kw), kw_r)), Some(value)) => {
|
if first_is_kw {
|
||||||
|
let (l, kw, r) = match self.elements.pop_front() {
|
||||||
|
Some(Sp(l, Expr::Keyword(kw), r)) => (l, kw, r),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
if let Some(value) = self.elements.pop_front() {
|
||||||
data.push((kw, value));
|
data.push((kw, value));
|
||||||
|
} else {
|
||||||
|
return if data.is_empty() {
|
||||||
|
Some(ExpressionElement::Single(Sp(l, Expr::Keyword(kw), r)))
|
||||||
|
} else {
|
||||||
|
Some(ExpressionElement::KeyValue(data))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
(Some(x), Some(y)) => {
|
} else {
|
||||||
self.elements.push_front(y);
|
return if data.is_empty() {
|
||||||
self.elements.push_front(x);
|
Some(ExpressionElement::Single(self.elements.pop_front()?))
|
||||||
break;
|
} else {
|
||||||
}
|
Some(ExpressionElement::KeyValue(data))
|
||||||
(Some(x), None) => {
|
};
|
||||||
self.elements.push_front(x);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(None, None) => break,
|
|
||||||
(None, Some(_)) => unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if data.is_empty() {
|
|
||||||
Some(ExpressionElement::Single(self.elements.pop_front()?))
|
|
||||||
} else {
|
|
||||||
Some(ExpressionElement::KeyValue(data))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,12 @@ impl Expr {
|
||||||
_ => Err(WrongExprType),
|
_ => Err(WrongExprType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn is_keyword(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Expr::Keyword(_) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Expr {
|
impl std::fmt::Display for Expr {
|
||||||
|
|
Loading…
Add table
Reference in a new issue