Skip to content

Commit

Permalink
refactor: use Linker::insert in Linker::resource
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Jan 3, 2024
1 parent 29bac89 commit 06f11f2
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions crates/wasmtime/src/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,12 @@ impl<T> LinkerInstance<'_, T> {
&self.engine,
move |mut cx: crate::Caller<'_, T>, param: u32| dtor(cx.as_context_mut(), param),
));
let entry = self.map.entry(name);
if !self.allow_shadowing && matches!(entry, Entry::Occupied(_)) {
bail!("import of `{}` defined twice", self.strings.strings[name])
}
let idx = ResourceImportIndex::new(*self.resource_imports);
*self.resource_imports = self
.resource_imports
.checked_add(1)
.context("resource import count would overflow")?;
let def = Definition::Resource(idx, ty, dtor);
match entry {
Entry::Occupied(mut o) => {
o.insert(def);
}
Entry::Vacant(v) => {
v.insert(def);
}
}
self.insert(name, Definition::Resource(idx, ty, dtor))?;
Ok(idx)
}

Expand Down

0 comments on commit 06f11f2

Please sign in to comment.