Skip to content

Commit 346b01f

Browse files
authored
Merge pull request #49 from ewasm/dumb_alloc
Introduce qimalloc as an allocator option
2 parents d53effc + 90a31e1 commit 346b01f

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ description = "ewasm API for Rust"
88
edition = "2018"
99

1010
[dependencies]
11-
wee_alloc = "0.4.4"
11+
cfg-if = "0.1.7"
12+
wee_alloc = { version = "0.4.4", optional = true }
13+
qimalloc = { version = "0.1", optional = true }
1214

1315
[features]
14-
default = [ "std" ]
16+
default = ["std", "wee_alloc"]
1517
std = []
1618
debug = []
1719
experimental = []

circle.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ jobs:
3434
cargo build --release --no-default-features --features experimental
3535
cargo build --release --features experimental,debug
3636
cargo build --release --no-default-features --features experimental,debug
37+
cargo build --release --features wee_alloc
38+
cargo build --release --features qimalloc

src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@
1919
/// finish_data(&a.bytes);
2020
/// }
2121
/// ```
22-
extern crate wee_alloc;
2322
24-
#[global_allocator]
25-
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
23+
#[macro_use]
24+
extern crate cfg_if;
25+
26+
cfg_if! {
27+
if #[cfg(feature = "wee_alloc")] {
28+
extern crate wee_alloc;
29+
#[global_allocator]
30+
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
31+
} else if #[cfg(feature = "qimalloc")] {
32+
extern crate qimalloc;
33+
#[global_allocator]
34+
static ALLOC: qimalloc::QIMalloc = qimalloc::QIMalloc::INIT;
35+
}
36+
}
2637

2738
mod native;
2839
pub mod types;

0 commit comments

Comments
 (0)