mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-03 10:51:09 +00:00
Zero out descriptor statics
This way postprocessing tools like `wasm-opt` can optimize out the data section altogether, dropping lots of zeros
This commit is contained in:
parent
9825b7a7c9
commit
8b2f34b51a
@ -6,7 +6,7 @@ extern crate wasm_gc;
|
|||||||
use std::char;
|
use std::char;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
@ -150,20 +150,22 @@ fn extract_programs(module: &mut Module) -> Vec<shared::Program> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for entry in data.entries_mut() {
|
for entry in data.entries_mut() {
|
||||||
let value = bytes_to_u32(entry.value_mut());
|
let mut value = bytes_to_u32(entry.value_mut());
|
||||||
let mut value = &*value;
|
let mut tmp = &mut *value;
|
||||||
loop {
|
loop {
|
||||||
match value.iter().position(|i| i.0 == 0x30d97887) {
|
let value = tmp;
|
||||||
Some(i) => value = &value[i + 1..],
|
let start = match value.iter().position(|i| i.0 == 0x30d97887) {
|
||||||
|
Some(i) => i,
|
||||||
None => break,
|
None => break,
|
||||||
}
|
};
|
||||||
if value.get(0).map(|c| c.0) != Some(0xd4182f61) {
|
if value.get(start + 1).map(|c| c.0) != Some(0xd4182f61) {
|
||||||
|
tmp = &mut value[1..];
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let cnt = value[1].0 as usize;
|
let cnt = value[start + 2].0 as usize;
|
||||||
let (a, b) = value[2..].split_at(cnt);
|
let (a, b) = value[start..].split_at_mut(cnt + 3);
|
||||||
value = b;
|
tmp = b;
|
||||||
let json = a.iter()
|
let json = a[3..].iter()
|
||||||
.map(|i| char::from_u32(i.0).unwrap())
|
.map(|i| char::from_u32(i.0).unwrap())
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
let p: shared::Program = match serde_json::from_str(&json) {
|
let p: shared::Program = match serde_json::from_str(&json) {
|
||||||
@ -198,6 +200,10 @@ to open an issue at https://github.com/alexcrichton/wasm-bindgen/issues!
|
|||||||
p.version, version);
|
p.version, version);
|
||||||
}
|
}
|
||||||
ret.push(p);
|
ret.push(p);
|
||||||
|
|
||||||
|
for slot in a {
|
||||||
|
slot.0 = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
@ -234,6 +240,15 @@ impl<'a> Deref for FutzWithAlign<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> DerefMut for FutzWithAlign<'a> {
|
||||||
|
fn deref_mut(&mut self) -> &mut [Unaligned] {
|
||||||
|
unsafe {
|
||||||
|
slice::from_raw_parts_mut(self.data.as_mut_ptr() as *mut Unaligned,
|
||||||
|
self.data.len() / 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Drop for FutzWithAlign<'a> {
|
impl<'a> Drop for FutzWithAlign<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.data.truncate(self.len);
|
self.data.truncate(self.len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user