Replace assert! with debug_assert! in production code paths.
This allows the assertions to be disabled in release builds, so that the code is faster and smaller, at the expense of not performing the checks. Assertions can be re-enabled in release builds with the debug-assertions flag in Cargo.toml, as the top-level Cargo.toml file does.
This commit is contained in:
@@ -211,7 +211,7 @@ def gen_instruction_data_impl(fmt):
|
||||
if f.has_value_list:
|
||||
fmt.line(n + ' { ref mut args, .. } => args,')
|
||||
fmt.line('_ => panic!("No value list: {:?}", self),')
|
||||
fmt.line('assert!(args.is_empty(), "Value list already in use");')
|
||||
fmt.line('debug_assert!(args.is_empty(), "Value list already in use");')
|
||||
fmt.line('*args = vlist;')
|
||||
|
||||
|
||||
|
||||
@@ -348,7 +348,8 @@ def gen_xform(xform, fmt, type_sets):
|
||||
# Delete the original instruction if we didn't have an opportunity to
|
||||
# replace it.
|
||||
if not replace_inst:
|
||||
fmt.line('assert_eq!(pos.remove_inst(), inst);')
|
||||
fmt.line('let removed = pos.remove_inst();')
|
||||
fmt.line('debug_assert_eq!(removed, inst);')
|
||||
fmt.line('return true;')
|
||||
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ def gen_constructor(sgrp, parent, fmt):
|
||||
'pub fn new({}) -> Flags {{'.format(args), '}'):
|
||||
fmt.line('let bvec = builder.state_for("{}");'.format(sgrp.name))
|
||||
fmt.line('let mut bytes = [0; {}];'.format(sgrp.byte_size()))
|
||||
fmt.line('assert_eq!(bvec.len(), {});'.format(sgrp.settings_size))
|
||||
fmt.line('debug_assert_eq!(bvec.len(), {});'.format(sgrp.settings_size))
|
||||
with fmt.indented(
|
||||
'for (i, b) in bvec.iter().enumerate() {', '}'):
|
||||
fmt.line('bytes[i] = *b;')
|
||||
|
||||
Reference in New Issue
Block a user