mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Optimize StringName usage
* Added a new macro SNAME() that constructs and caches a local stringname. * Subsequent usages use the cached version. * Since these use a global static variable, a second refcounter of static usages need to be kept for cleanup time. * Replaced all theme usages by this new macro. * Replace all signal emission usages by this new macro. * Replace all call_deferred usages by this new macro. This is part of ongoing work to optimize GUI and the editor.
This commit is contained in:
parent
b76dfde329
commit
6631f66c2a
236 changed files with 3694 additions and 3670 deletions
|
@ -116,12 +116,12 @@ void FindInFiles::_notification(int p_notification) {
|
|||
void FindInFiles::start() {
|
||||
if (_pattern == "") {
|
||||
print_verbose("Nothing to search, pattern is empty");
|
||||
emit_signal(SIGNAL_FINISHED);
|
||||
emit_signal(SNAME(SIGNAL_FINISHED));
|
||||
return;
|
||||
}
|
||||
if (_extension_filter.size() == 0) {
|
||||
print_verbose("Nothing to search, filter matches no files");
|
||||
emit_signal(SIGNAL_FINISHED);
|
||||
emit_signal(SNAME(SIGNAL_FINISHED));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ void FindInFiles::_iterate() {
|
|||
set_process(false);
|
||||
_current_dir = "";
|
||||
_searching = false;
|
||||
emit_signal(SIGNAL_FINISHED);
|
||||
emit_signal(SNAME(SIGNAL_FINISHED));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ void FindInFiles::_scan_file(String fpath) {
|
|||
String line = f->get_line();
|
||||
|
||||
while (find_next(line, _pattern, end, _match_case, _whole_words, begin, end)) {
|
||||
emit_signal(SIGNAL_RESULT_FOUND, fpath, line_number, begin, end, line);
|
||||
emit_signal(SNAME(SIGNAL_RESULT_FOUND), fpath, line_number, begin, end, line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ void FindInFilesDialog::_notification(int p_what) {
|
|||
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
if (is_visible()) {
|
||||
// Doesn't work more than once if not deferred...
|
||||
_search_text_line_edit->call_deferred("grab_focus");
|
||||
_search_text_line_edit->call_deferred(SNAME("grab_focus"));
|
||||
_search_text_line_edit->select_all();
|
||||
// Extensions might have changed in the meantime, we clean them and instance them again.
|
||||
for (int i = 0; i < _filters_container->get_child_count(); i++) {
|
||||
|
@ -487,10 +487,10 @@ void FindInFilesDialog::custom_action(const String &p_action) {
|
|||
_filters_preferences[cb->get_text()] = cb->is_pressed();
|
||||
}
|
||||
if (p_action == "find") {
|
||||
emit_signal(SIGNAL_FIND_REQUESTED);
|
||||
emit_signal(SNAME(SIGNAL_FIND_REQUESTED));
|
||||
hide();
|
||||
} else if (p_action == "replace") {
|
||||
emit_signal(SIGNAL_REPLACE_REQUESTED);
|
||||
emit_signal(SNAME(SIGNAL_REPLACE_REQUESTED));
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
@ -565,8 +565,8 @@ FindInFilesPanel::FindInFilesPanel() {
|
|||
hbc->add_child(find_label);
|
||||
|
||||
_search_text_label = memnew(Label);
|
||||
_search_text_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts"));
|
||||
_search_text_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("source_size", "EditorFonts"));
|
||||
_search_text_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("source"), SNAME("EditorFonts")));
|
||||
_search_text_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("source_size"), SNAME("EditorFonts")));
|
||||
hbc->add_child(_search_text_label);
|
||||
|
||||
_progress_bar = memnew(ProgressBar);
|
||||
|
@ -594,8 +594,8 @@ FindInFilesPanel::FindInFilesPanel() {
|
|||
}
|
||||
|
||||
_results_display = memnew(Tree);
|
||||
_results_display->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts"));
|
||||
_results_display->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("source_size", "EditorFonts"));
|
||||
_results_display->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("source"), SNAME("EditorFonts")));
|
||||
_results_display->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("source_size"), SNAME("EditorFonts")));
|
||||
_results_display->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
_results_display->connect("item_selected", callable_mp(this, &FindInFilesPanel::_on_result_selected));
|
||||
_results_display->connect("item_edited", callable_mp(this, &FindInFilesPanel::_on_item_edited));
|
||||
|
@ -688,8 +688,8 @@ void FindInFilesPanel::_notification(int p_what) {
|
|||
if (p_what == NOTIFICATION_PROCESS) {
|
||||
_progress_bar->set_as_ratio(_finder->get_progress());
|
||||
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
_search_text_label->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
|
||||
_results_display->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
|
||||
_search_text_label->add_theme_font_override("font", get_theme_font(SNAME("source"), SNAME("EditorFonts")));
|
||||
_results_display->add_theme_font_override("font", get_theme_font(SNAME("source"), SNAME("EditorFonts")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,8 +754,8 @@ void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) {
|
|||
}
|
||||
Result r = E->value();
|
||||
String item_text = item->get_text(_with_replace ? 1 : 0);
|
||||
Ref<Font> font = _results_display->get_theme_font("font");
|
||||
int font_size = _results_display->get_theme_font_size("font_size");
|
||||
Ref<Font> font = _results_display->get_theme_font(SNAME("font"));
|
||||
int font_size = _results_display->get_theme_font_size(SNAME("font_size"));
|
||||
|
||||
Rect2 match_rect = rect;
|
||||
match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), font_size).x;
|
||||
|
@ -764,7 +764,7 @@ void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) {
|
|||
match_rect.size.y -= 2 * EDSCALE;
|
||||
|
||||
// Use the inverted accent color to help match rectangles stand out even on the currently selected line.
|
||||
_results_display->draw_rect(match_rect, get_theme_color("accent_color", "Editor").inverted() * Color(1, 1, 1, 0.5));
|
||||
_results_display->draw_rect(match_rect, get_theme_color(SNAME("accent_color"), SNAME("Editor")).inverted() * Color(1, 1, 1, 0.5));
|
||||
|
||||
// Text is drawn by Tree already.
|
||||
}
|
||||
|
@ -773,11 +773,11 @@ void FindInFilesPanel::_on_item_edited() {
|
|||
TreeItem *item = _results_display->get_selected();
|
||||
|
||||
if (item->is_checked(0)) {
|
||||
item->set_custom_color(1, _results_display->get_theme_color("font_color"));
|
||||
item->set_custom_color(1, _results_display->get_theme_color(SNAME("font_color")));
|
||||
|
||||
} else {
|
||||
// Grey out
|
||||
Color color = _results_display->get_theme_color("font_color");
|
||||
Color color = _results_display->get_theme_color(SNAME("font_color"));
|
||||
color.a /= 2.0;
|
||||
item->set_custom_color(1, color);
|
||||
}
|
||||
|
@ -823,7 +823,7 @@ void FindInFilesPanel::_on_result_selected() {
|
|||
TreeItem *file_item = item->get_parent();
|
||||
String fpath = file_item->get_metadata(0);
|
||||
|
||||
emit_signal(SIGNAL_RESULT_SELECTED, fpath, r.line_number, r.begin, r.end);
|
||||
emit_signal(SNAME(SIGNAL_RESULT_SELECTED), fpath, r.line_number, r.begin, r.end);
|
||||
}
|
||||
|
||||
void FindInFilesPanel::_on_replace_text_changed(String text) {
|
||||
|
@ -860,7 +860,7 @@ void FindInFilesPanel::_on_replace_all_clicked() {
|
|||
// Hide replace bar so we can't trigger the action twice without doing a new search
|
||||
_replace_container->hide();
|
||||
|
||||
emit_signal(SIGNAL_FILES_MODIFIED, modified_files);
|
||||
emit_signal(SNAME(SIGNAL_FILES_MODIFIED), modified_files);
|
||||
}
|
||||
|
||||
// Same as get_line, but preserves line ending characters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue