mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-04 19:08:32 +00:00
avoid checking for downcasters in ingredient cache slow-path
This commit is contained in:
parent
2e818365dd
commit
93b152d9de
2 changed files with 16 additions and 2 deletions
|
@ -151,8 +151,14 @@ macro_rules! setup_tracked_fn {
|
|||
fn fn_ingredient(db: &dyn $Db) -> &$zalsa::function::IngredientImpl<$Configuration> {
|
||||
let zalsa = db.zalsa();
|
||||
$FN_CACHE.get_or_create(zalsa, || {
|
||||
<dyn $Db as $Db>::zalsa_register_downcaster(db);
|
||||
zalsa.add_or_lookup_jar_by_type::<$Configuration>()
|
||||
// If the ingredient has already been inserted, we know that the downcaster
|
||||
// has also been registered. This is a fast-path for multi-database use cases
|
||||
// that bypass the ingredient cache and will always execute this closure.
|
||||
zalsa.lookup_jar_by_type::<$Configuration>()
|
||||
.unwrap_or_else(|| {
|
||||
<dyn $Db as $Db>::zalsa_register_downcaster(db);
|
||||
zalsa.add_or_lookup_jar_by_type::<$Configuration>()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -296,6 +296,14 @@ impl Zalsa {
|
|||
.expect("should have the ingredient index available")
|
||||
}
|
||||
|
||||
/// **NOT SEMVER STABLE**
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
pub fn lookup_jar_by_type<J: Jar>(&self) -> Option<IngredientIndex> {
|
||||
let jar_type_id = TypeId::of::<J>();
|
||||
self.jar_map.get(&jar_type_id, &self.jar_map.guard())
|
||||
}
|
||||
|
||||
/// **NOT SEMVER STABLE**
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue