Skip to content

Commit

Permalink
Changed externref_table to use geometric resizing, giving amortized O…
Browse files Browse the repository at this point in the history
…(1) insertions (#2294)
  • Loading branch information
richardlett committed Aug 24, 2020
1 parent 0cd5f16 commit 520e2ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/externref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::mem;
use std::ptr;
use std::slice;
use std::vec::Vec;
use std::cmp::max;

externs! {
#[link(wasm_import_module = "__wbindgen_externref_xform__")]
Expand Down Expand Up @@ -32,8 +33,9 @@ impl Slab {
fn alloc(&mut self) -> usize {
let ret = self.head;
if ret == self.data.len() {
if self.data.len() == self.data.capacity() {
let extra = 128;
let curr_len = self.data.len();
if curr_len == self.data.capacity() {
let extra = max(128, curr_len);
let r = unsafe { __wbindgen_externref_table_grow(extra) };
if r == -1 {
internal_error("table grow failure")
Expand Down

0 comments on commit 520e2ad

Please sign in to comment.