(function: &BNFunction, f: F)
| 38 | } |
| 39 | |
| 40 | pub fn cached_function_match<F>(function: &BNFunction, f: F) -> Option<Function> |
| 41 | where |
| 42 | F: Fn() -> Option<Function>, |
| 43 | { |
| 44 | let view = function.view(); |
| 45 | let view_id = ViewID::from(view.as_ref()); |
| 46 | let function_id = FunctionID::from(function); |
| 47 | let function_cache = MATCHED_FUNCTION_CACHE.get_or_init(Default::default); |
| 48 | match function_cache.get(&view_id) { |
| 49 | Some(cache) => cache.get_or_insert(&function_id, f).to_owned(), |
| 50 | None => { |
| 51 | let cache = MatchedFunctionCache::default(); |
| 52 | let matched = cache.get_or_insert(&function_id, f).to_owned(); |
| 53 | function_cache.insert(view_id, cache); |
| 54 | matched |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | pub fn try_cached_function_match(function: &BNFunction) -> Option<Function> { |
| 60 | let view = function.view(); |
no test coverage detected