only assert in debug builds
these are primarily used to detect bugs during e.g. fuzzing. most of these asserts have negligible impact on performance, but if they are not debug asserts it is not obvious that they dont affect performance of release builds
This commit is contained in:
parent
3f011b9367
commit
1e5e56c463
5 changed files with 12 additions and 12 deletions
|
@ -215,7 +215,7 @@ impl<'s> TreeParser<'s> {
|
||||||
|
|
||||||
// close list if a non list item or a list item of new type appeared
|
// close list if a non list item or a list item of new type appeared
|
||||||
if let Some(OpenList { ty, depth, .. }) = self.open_lists.last() {
|
if let Some(OpenList { ty, depth, .. }) = self.open_lists.last() {
|
||||||
assert!(usize::from(*depth) <= self.tree.depth());
|
debug_assert!(usize::from(*depth) <= self.tree.depth());
|
||||||
if self.tree.depth() == (*depth).into()
|
if self.tree.depth() == (*depth).into()
|
||||||
&& !matches!(kind, Kind::ListItem { ty: ty_new, .. } if *ty == ty_new)
|
&& !matches!(kind, Kind::ListItem { ty: ty_new, .. } if *ty == ty_new)
|
||||||
{
|
{
|
||||||
|
@ -405,7 +405,7 @@ impl<'s> TreeParser<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(OpenList { depth, .. }) = self.open_lists.last() {
|
if let Some(OpenList { depth, .. }) = self.open_lists.last() {
|
||||||
assert!(usize::from(*depth) <= self.tree.depth());
|
debug_assert!(usize::from(*depth) <= self.tree.depth());
|
||||||
if self.tree.depth() == (*depth).into() {
|
if self.tree.depth() == (*depth).into() {
|
||||||
self.prev_blankline = false;
|
self.prev_blankline = false;
|
||||||
self.prev_loose = false;
|
self.prev_loose = false;
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl Render for Renderer {
|
||||||
Container::DescriptionList => out.write_str("<dl")?,
|
Container::DescriptionList => out.write_str("<dl")?,
|
||||||
Container::DescriptionDetails => out.write_str("<dd")?,
|
Container::DescriptionDetails => out.write_str("<dd")?,
|
||||||
Container::Footnote { number, .. } => {
|
Container::Footnote { number, .. } => {
|
||||||
assert!(self.footnote_number.is_none());
|
debug_assert!(self.footnote_number.is_none());
|
||||||
self.footnote_number = Some((*number).try_into().unwrap());
|
self.footnote_number = Some((*number).try_into().unwrap());
|
||||||
if !self.encountered_footnote {
|
if !self.encountered_footnote {
|
||||||
self.encountered_footnote = true;
|
self.encountered_footnote = true;
|
||||||
|
|
|
@ -504,7 +504,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
assert_eq!(self.events[e_opener].span, event_closer.span);
|
debug_assert_eq!(self.events[e_opener].span, event_closer.span);
|
||||||
event_closer.span = inner_span;
|
event_closer.span = inner_span;
|
||||||
self.events[e_opener].span = inner_span;
|
self.events[e_opener].span = inner_span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -993,7 +993,7 @@ impl<'s> Parser<'s> {
|
||||||
class: (!ev.span.is_empty()).then(|| content),
|
class: (!ev.span.is_empty()).then(|| content),
|
||||||
},
|
},
|
||||||
block::Container::Footnote => {
|
block::Container::Footnote => {
|
||||||
assert!(enter);
|
debug_assert!(enter);
|
||||||
self.footnotes.insert(content, self.tree.take_branch());
|
self.footnotes.insert(content, self.tree.take_branch());
|
||||||
self.block_attributes = Attributes::new();
|
self.block_attributes = Attributes::new();
|
||||||
continue;
|
continue;
|
||||||
|
|
14
src/tree.rs
14
src/tree.rs
|
@ -79,7 +79,7 @@ impl<C: Clone, A: Clone> Tree<C, A> {
|
||||||
std::iter::from_fn(move || {
|
std::iter::from_fn(move || {
|
||||||
head.take().map(|h| {
|
head.take().map(|h| {
|
||||||
let n = &self.nodes[h.index()];
|
let n = &self.nodes[h.index()];
|
||||||
assert!(matches!(n.kind, NodeKind::Inline));
|
debug_assert!(matches!(n.kind, NodeKind::Inline));
|
||||||
head = n.next;
|
head = n.next;
|
||||||
n.span
|
n.span
|
||||||
})
|
})
|
||||||
|
@ -126,7 +126,7 @@ pub struct NodeIndex(std::num::NonZeroUsize);
|
||||||
|
|
||||||
impl NodeIndex {
|
impl NodeIndex {
|
||||||
fn new(i: usize) -> Self {
|
fn new(i: usize) -> Self {
|
||||||
assert_ne!(i, usize::MAX);
|
debug_assert_ne!(i, usize::MAX);
|
||||||
Self((i + 1).try_into().unwrap())
|
Self((i + 1).try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ impl<C, A> Builder<C, A> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let last = self.branch.pop();
|
let last = self.branch.pop();
|
||||||
assert_ne!(last, None);
|
debug_assert_ne!(last, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ impl<C, A> Builder<C, A> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn finish(self) -> Tree<C, A> {
|
pub(super) fn finish(self) -> Tree<C, A> {
|
||||||
assert_eq!(self.depth, 0);
|
debug_assert_eq!(self.depth, 0);
|
||||||
let head = self.nodes[NodeIndex::root().index()].next;
|
let head = self.nodes[NodeIndex::root().index()].next;
|
||||||
Tree {
|
Tree {
|
||||||
nodes: self.nodes.into_boxed_slice().into(),
|
nodes: self.nodes.into_boxed_slice().into(),
|
||||||
|
@ -331,19 +331,19 @@ impl<C, A> Builder<C, A> {
|
||||||
match &mut head.kind {
|
match &mut head.kind {
|
||||||
NodeKind::Root | NodeKind::Inline | NodeKind::Atom(_) => {
|
NodeKind::Root | NodeKind::Inline | NodeKind::Atom(_) => {
|
||||||
// set next pointer of previous node
|
// set next pointer of previous node
|
||||||
assert_eq!(head.next, None);
|
debug_assert_eq!(head.next, None);
|
||||||
head.next = Some(ni);
|
head.next = Some(ni);
|
||||||
}
|
}
|
||||||
NodeKind::Container(_, child) => {
|
NodeKind::Container(_, child) => {
|
||||||
self.branch.push(*head_ni);
|
self.branch.push(*head_ni);
|
||||||
// set child pointer of current container
|
// set child pointer of current container
|
||||||
assert_eq!(*child, None);
|
debug_assert_eq!(*child, None);
|
||||||
*child = Some(ni);
|
*child = Some(ni);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(block) = self.branch.pop() {
|
} else if let Some(block) = self.branch.pop() {
|
||||||
let mut block = &mut self.nodes[block.index()];
|
let mut block = &mut self.nodes[block.index()];
|
||||||
assert!(matches!(block.kind, NodeKind::Container(..)));
|
debug_assert!(matches!(block.kind, NodeKind::Container(..)));
|
||||||
block.next = Some(ni);
|
block.next = Some(ni);
|
||||||
} else {
|
} else {
|
||||||
panic!()
|
panic!()
|
||||||
|
|
Loading…
Reference in a new issue