mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-30 19:41:56 +00:00
Adding in unintern function (#1828)
* Adding in unintern function * Adding in some basic unit tests for interning and uninterning
This commit is contained in:
21
src/cache/intern.rs
vendored
21
src/cache/intern.rs
vendored
@@ -40,6 +40,14 @@ cfg_if! {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn unintern_str(key: &str) {
|
||||
CACHE.with(|cache| {
|
||||
let mut cache = cache.entries.borrow_mut();
|
||||
|
||||
cache.remove(key);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,3 +88,16 @@ pub fn intern(s: &str) -> &str {
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
|
||||
/// Removes a Rust string from the intern cache.
|
||||
///
|
||||
/// This does the opposite of the [`intern`](fn.intern.html) function.
|
||||
///
|
||||
/// If the [`intern`](fn.intern.html) function is called again then it will re-intern the string.
|
||||
#[allow(unused_variables)]
|
||||
#[inline]
|
||||
pub fn unintern(s: &str) {
|
||||
#[cfg(feature = "enable-interning")]
|
||||
unintern_str(s);
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ if_std! {
|
||||
mod anyref;
|
||||
|
||||
mod cache;
|
||||
pub use cache::intern::intern;
|
||||
pub use cache::intern::{intern, unintern};
|
||||
}
|
||||
|
||||
/// Representation of an object owned by JS.
|
||||
|
Reference in New Issue
Block a user