mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Merge pull request #986 from alexcrichton/gc-types
Eliminate duplicate types in the type section
This commit is contained in:
commit
a0a9ed4686
@ -11,6 +11,6 @@ Support for removing unused items from a wasm executable
|
||||
"""
|
||||
|
||||
[dependencies]
|
||||
parity-wasm = "0.35"
|
||||
parity-wasm = "0.35.1"
|
||||
log = "0.4"
|
||||
rustc-demangle = "0.1.9"
|
||||
|
@ -8,7 +8,7 @@ extern crate parity_wasm;
|
||||
extern crate log;
|
||||
extern crate rustc_demangle;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashSet, HashMap};
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
|
||||
@ -474,14 +474,20 @@ impl<'a> RemapContext<'a> {
|
||||
let mut memories = Vec::new();
|
||||
|
||||
if let Some(s) = m.type_section() {
|
||||
let mut removed = 0;
|
||||
for i in 0..(s.types().len() as u32) {
|
||||
if analysis.types.contains(&i) {
|
||||
types.push(i - removed);
|
||||
let mut ntypes = 0;
|
||||
let mut map = HashMap::new();
|
||||
for (i, ty) in s.types().iter().enumerate() {
|
||||
if analysis.types.contains(&(i as u32)) {
|
||||
if let Some(prev) = map.get(&ty) {
|
||||
types.push(*prev);
|
||||
continue
|
||||
}
|
||||
map.insert(ty, ntypes);
|
||||
types.push(ntypes);
|
||||
ntypes += 1;
|
||||
} else {
|
||||
debug!("gc type {}", i);
|
||||
types.push(u32::max_value());
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user