Skip to content

Commit 18df2ae

Browse files
committed
Add class icon cache to EditorNode
1 parent 6c9765d commit 18df2ae

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
@@ -3986,9 +3986,10 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) {
39863986
}
39873987

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

39933994
if (editor_data.get_edited_scene() == index) {
39943995
// Scene to remove is current scene.
@@ -5140,6 +5141,13 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
51405141

51415142
Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) {
51425143
ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
5144+
// Take from the local cache, if available.
5145+
{
5146+
Ref<Texture2D> *icon = class_icon_cache.getptr(p_class);
5147+
if (icon) {
5148+
return *icon;
5149+
}
5150+
}
51435151

51445152
String script_path;
51455153
if (ScriptServer::is_global_class(p_class)) {
@@ -5148,7 +5156,9 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
51485156
script_path = p_class;
51495157
}
51505158

5151-
return _get_class_or_script_icon(p_class, script_path, p_fallback, true);
5159+
Ref<Texture2D> icon = _get_class_or_script_icon(p_class, script_path, p_fallback, true);
5160+
class_icon_cache[p_class] = icon;
5161+
return icon;
51525162
}
51535163

51545164
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)