debug_assert! instead of assert!

This reduces binary size
This commit is contained in:
강동윤 2019-01-10 18:54:40 +09:00
parent 7aee29d91d
commit 1fabc3fa3e
9 changed files with 16 additions and 16 deletions

View File

@ -61,7 +61,7 @@ impl<'a> Input for SourceFileInput<'a> {
}
fn slice(&mut self, start: BytePos, end: BytePos) -> &str {
assert!(start <= end, "Cannot slice {:?}..{:?}", start, end);
debug_assert!(start <= end, "Cannot slice {:?}..{:?}", start, end);
let s = self.orig;
let start_idx = (start - self.fm.start_pos).0 as usize;

View File

@ -283,7 +283,7 @@ impl<'a, I: Input> Lexer<'a, I> {
/// `#`
fn read_token_number_sign(&mut self) -> LexResult<Option<Token>> {
assert!(self.cur().is_some());
debug_assert!(self.cur().is_some());
let start = self.input.cur_pos();
@ -458,7 +458,7 @@ impl<'a, I: Input> Lexer<'a, I> {
}
fn read_token_lt_gt(&mut self) -> LexResult<Option<Token>> {
assert!(self.cur() == Some('<') || self.cur() == Some('>'));
debug_assert!(self.cur() == Some('<') || self.cur() == Some('>'));
let start = self.cur_pos();
let c = self.cur().unwrap();
@ -506,7 +506,7 @@ impl<'a, I: Input> Lexer<'a, I> {
/// See https://tc39.github.io/ecma262/#sec-names-and-keywords
fn read_ident_or_keyword(&mut self) -> LexResult<Token> {
assert!(self.cur().is_some());
debug_assert!(self.cur().is_some());
let start = self.cur_pos();
let (word, has_escape) = self.read_word_as_str()?;
@ -534,7 +534,7 @@ impl<'a, I: Input> Lexer<'a, I> {
/// returns (word, has_escape)
fn read_word_as_str(&mut self) -> LexResult<(JsWord, bool)> {
assert!(self.cur().is_some());
debug_assert!(self.cur().is_some());
let mut has_escape = false;
let mut word = String::new();
@ -637,7 +637,7 @@ impl<'a, I: Input> Lexer<'a, I> {
/// See https://tc39.github.io/ecma262/#sec-literals-string-literals
fn read_str_lit(&mut self) -> LexResult<Token> {
assert!(self.cur() == Some('\'') || self.cur() == Some('"'));
debug_assert!(self.cur() == Some('\'') || self.cur() == Some('"'));
let start = self.cur_pos();
let quote = self.cur().unwrap();
self.bump(); // '"'

View File

@ -10,7 +10,7 @@ use std::fmt::Display;
impl<'a, I: Input> Lexer<'a, I> {
/// Reads an integer, octal integer, or floating-point number
pub(super) fn read_number(&mut self, starts_with_dot: bool) -> LexResult<f64> {
assert!(self.cur().is_some());
debug_assert!(self.cur().is_some());
if starts_with_dot {
debug_assert_eq!(
self.cur(),

View File

@ -548,7 +548,7 @@ impl<'a, I: Input> Parser<'a, I> {
expr,
}));
} else {
assert!(expr_or_spreads.len() >= 2);
debug_assert!(expr_or_spreads.len() >= 2);
let mut exprs = Vec::with_capacity(expr_or_spreads.len());
for expr in expr_or_spreads {
@ -560,7 +560,7 @@ impl<'a, I: Input> Parser<'a, I> {
ExprOrSpread { expr, .. } => exprs.push(expr),
}
}
assert!(exprs.len() >= 2);
debug_assert!(exprs.len() >= 2);
// span of sequence expression should not include '(', ')'
let seq_expr = box Expr::Seq(SeqExpr {
@ -1091,7 +1091,7 @@ impl<'a, I: Input> Parser<'a, I> {
let start = cur_pos!();
assert_and_bump!("yield");
assert!(self.ctx().in_generator);
debug_assert!(self.ctx().in_generator);
// Spec says
// YieldExpression cannot be used within the FormalParameters of a generator

View File

@ -206,7 +206,7 @@ impl<'a, I: Input> Parser<'a, I> {
let start = cur_pos!();
assert_and_bump!("await");
assert!(self.ctx().in_async);
debug_assert!(self.ctx().in_async);
if is!('*') {
syntax_error!(SyntaxError::AwaitStar);

View File

@ -63,7 +63,7 @@ impl<'a, I: Input> ParserInput<'a, I> {
}
pub fn peek(&mut self) -> Option<&Token> {
assert!(
debug_assert!(
self.cur.is_some(),
"parser should not call peek() without knowing current token"
);

View File

@ -368,7 +368,7 @@ impl<'a, I: Input> Parser<'a, I> {
pub(super) fn parse_jsx_text(&mut self) -> PResult<'a, JSXText> {
debug_assert!(self.input.syntax().jsx());
assert!({
debug_assert!({
match *cur!(false)? {
Token::JSXText { .. } => true,
_ => false,

View File

@ -211,7 +211,7 @@ macro_rules! cur {
macro_rules! peek {
($p:expr) => {{
assert!(
debug_assert!(
$p.input.knows_cur(),
"parser should not call peek() without knowing current token.
Current token is {:?}",
@ -236,7 +236,7 @@ Current token is {:?}",
macro_rules! bump {
($p:expr) => {{
assert!(
debug_assert!(
$p.input.knows_cur(),
"parser should not call bump() without knowing current token"
);

View File

@ -591,7 +591,7 @@ impl<'a, I: Input> Parser<'a, I> {
debug_assert!(self.input.syntax().typescript());
// Need to set `state.inType` so that we don't parse JSX in a type context.
assert!(self.ctx().in_type);
debug_assert!(self.ctx().in_type);
let start = cur_pos!();