Skip to content

Commit f5bf37a

Browse files
committed
Merge pull request godotengine#106866 from KoBeWi/more_cache
Add class icon cache to EditorNode
2 parents 90c75d0 + 18df2ae commit f5bf37a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

editor/editor_data.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,13 @@ Ref<Texture2D> EditorData::_load_script_icon(const String &p_path) const {
11161116

11171117
Ref<Texture2D> EditorData::get_script_icon(const String &p_script_path) {
11181118
// Take from the local cache, if available.
1119-
if (_script_icon_cache.has(p_script_path)) {
1120-
// Can be an empty value if we can't resolve any icon for this script.
1121-
// An empty value is still cached to avoid unnecessary attempts at resolving it again.
1122-
return _script_icon_cache[p_script_path];
1119+
{
1120+
Ref<Texture2D> *icon = _script_icon_cache.getptr(p_script_path);
1121+
if (icon) {
1122+
// Can be an empty value if we can't resolve any icon for this script.
1123+
// An empty value is still cached to avoid unnecessary attempts at resolving it again.
1124+
return *icon;
1125+
}
11231126
}
11241127

11251128
// Fast path in case the whole hierarchy is made of global classes.

editor/editor_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class EditorData {
146146

147147
HashMap<StringName, String> _script_class_icon_paths;
148148
HashMap<String, StringName> _script_class_file_to_path;
149-
HashMap<String, Ref<Texture>> _script_icon_cache;
149+
HashMap<String, Ref<Texture2D>> _script_icon_cache;
150150

151151
Ref<Texture2D> _load_script_icon(const String &p_path) const;
152152

editor/editor_node.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,9 +4005,10 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) {
40054005
}
40064006

40074007
void EditorNode::_remove_scene(int index, bool p_change_tab) {
4008-
// Clear icon cache in case some scripts are no longer needed.
4008+
// Clear icon cache in case some scripts are no longer needed or class icons are outdated.
40094009
// FIXME: Ideally the cache should never be cleared and only updated on per-script basis, when an icon changes.
40104010
editor_data.clear_script_icon_cache();
4011+
class_icon_cache.clear();
40114012

40124013
if (editor_data.get_edited_scene() == index) {
40134014
// Scene to remove is current scene.
@@ -5188,6 +5189,13 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
51885189

51895190
Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) {
51905191
ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
5192+
// Take from the local cache, if available.
5193+
{
5194+
Ref<Texture2D> *icon = class_icon_cache.getptr(p_class);
5195+
if (icon) {
5196+
return *icon;
5197+
}
5198+
}
51915199

51925200
String script_path;
51935201
if (ScriptServer::is_global_class(p_class)) {
@@ -5196,7 +5204,9 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
51965204
script_path = p_class;
51975205
}
51985206

5199-
return _get_class_or_script_icon(p_class, script_path, p_fallback, true);
5207+
Ref<Texture2D> icon = _get_class_or_script_icon(p_class, script_path, p_fallback, true);
5208+
class_icon_cache[p_class] = icon;
5209+
return icon;
52005210
}
52015211

52025212
bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {

editor/editor_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ class EditorNode : public Node {
484484
PrintHandlerList print_handler;
485485

486486
HashMap<String, Ref<Texture2D>> icon_type_cache;
487+
HashMap<String, Ref<Texture2D>> class_icon_cache;
487488

488489
ProjectUpgradeTool *project_upgrade_tool = nullptr;
489490
bool run_project_upgrade_tool = false;

0 commit comments

Comments
 (0)