(text: &str)
| 37 | (*cached_scene_doc_shared(text)).clone() |
| 38 | } |
| 39 | |
| 40 | pub fn cached_scene_doc_shared(text: &str) -> Arc<SceneDoc> { |
| 41 | let cache = ACTIVE_SCENE_DOC_CACHE.get_or_init(|| Mutex::new(Vec::new())); |
| 42 | let Ok(mut guard) = cache.lock() else { |
| 43 | return Arc::new(SceneDoc::parse(text)); |
| 44 | }; |
| 45 | if let Some(idx) = guard.iter().position(|cached| cached.text == text) { |
| 46 | let cached = guard.remove(idx); |
| 47 | let doc = cached.doc.clone(); |
| 48 | guard.push(cached); |
| 49 | return doc; |
| 50 | } |
| 51 | let doc = Arc::new(SceneDoc::parse(text)); |
| 52 | guard.push(CachedSceneDoc::new(text.to_string(), doc.clone())); |
| 53 | if guard.len() > SCENE_DOC_CACHE_LIMIT { |
| 54 | guard.remove(0); |
| 55 | } |
| 56 | doc |
| 57 | } |
| 58 | |
| 59 | pub fn store_scene_doc_cache(text: &str, doc: &SceneDoc) { |
no test coverage detected