Skip to content

Commit a8f42e4

Browse files
chore: share passive data segments across instances
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent e5f234b commit a8f42e4

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

crates/parser/src/conversion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn convert_module_data(
5555
global_types: &[WasmType],
5656
) -> Result<tinywasm_types::Data> {
5757
Ok(tinywasm_types::Data {
58-
data: data.data.to_vec().into_boxed_slice(),
58+
data: data.data.into(),
5959
range: data.range,
6060
kind: match data.kind {
6161
wasmparser::DataKind::Active { memory_index, offset_expr } => {

crates/tinywasm/src/store/data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use alloc::vec::Vec;
1+
use tinywasm_types::Shared;
22

33
/// A WebAssembly Data Instance
44
///
55
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#data-instances>
66
#[cfg_attr(feature = "debug", derive(Debug))]
77
pub(crate) struct DataInstance {
8-
pub(crate) data: Option<Vec<u8>>,
8+
pub(crate) data: Option<Shared<[u8]>>,
99
}
1010

1111
impl DataInstance {

crates/tinywasm/src/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl Store {
747747
}
748748
}
749749
}
750-
tinywasm_types::DataKind::Passive => Some(data.data.to_vec()),
750+
tinywasm_types::DataKind::Passive => Some(data.data.clone()),
751751
};
752752

753753
self.state.data.push(DataInstance { data: data_val });

crates/types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ impl From<&ImportKind> for ExternalKind {
750750
#[cfg_attr(feature = "debug", derive(Debug))]
751751
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
752752
pub struct Data {
753-
pub data: Box<[u8]>,
753+
pub data: Shared<[u8]>,
754754
pub range: Range<u64>,
755755
pub kind: DataKind,
756756
}

0 commit comments

Comments
 (0)