Hash trap message symbol nameThis saves ~7% of disk space
This commit is contained in:
parent
1c02e6c368
commit
4d226e8f17
@ -1,3 +1,6 @@
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
|
||||
@ -21,12 +24,15 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
|
||||
|
||||
let symbol_name = fx.tcx.symbol_name(fx.instance);
|
||||
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
|
||||
let mut hasher = DefaultHasher::new();
|
||||
real_msg.hash(&mut hasher);
|
||||
let msg_hash = hasher.finish();
|
||||
let mut data_ctx = DataContext::new();
|
||||
data_ctx.define(real_msg.as_bytes().to_vec().into_boxed_slice());
|
||||
let msg_id = fx
|
||||
.module
|
||||
.declare_data(
|
||||
&(symbol_name.name.as_str().to_string() + msg),
|
||||
&format!("__trap_{:08x}", msg_hash),
|
||||
Linkage::Local,
|
||||
false,
|
||||
false,
|
||||
|
Loading…
Reference in New Issue
Block a user