MCPcopy Create free account
hub / github.com/PerroEngine/Perro / cached_scene_node

Function cached_scene_node

perro_editor/res/scripts/editor/main.rs:97–121  ·  view source on GitHub ↗
(text: &str, key: u32)

Source from the content-addressed store, hash-verified

95 }
96}
97
98pub fn cached_scene_node(text: &str, key: u32) -> Option<SceneNodeEntry> {
99 let cache = ACTIVE_SCENE_DOC_CACHE.get_or_init(|| Mutex::new(Vec::new()));
100 let Ok(mut guard) = cache.lock() else {
101 return SceneDoc::parse(text)
102 .scene
103 .nodes
104 .iter()
105 .find(|node| node.key.as_u32() == key)
106 .cloned();
107 };
108 if let Some(idx) = guard.iter().position(|cached| cached.text == text) {
109 let cached = guard.remove(idx);
110 let node = cached.node(key);
111 guard.push(cached);
112 return node;
113 }
114 let doc = Arc::new(SceneDoc::parse(text));
115 let cached = CachedSceneDoc::new(text.to_string(), doc);
116 let node = cached.node(key);
117 guard.push(cached);
118 if guard.len() > SCENE_DOC_CACHE_LIMIT {
119 guard.remove(0);
120 }
121 node
122}
123
124pub fn set_state_scene_doc(state: &mut EditorState, doc: &SceneDoc) {

Callers 5

selected_node_field_textFunction · 0.85
quick_asset_stemFunction · 0.85
from_stateMethod · 0.85
picker_parent_textFunction · 0.85

Calls 9

findMethod · 0.80
parseFunction · 0.50
iterMethod · 0.45
as_u32Method · 0.45
positionMethod · 0.45
removeMethod · 0.45
nodeMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected