From 746dddc0673d7261f19b1e056e90e6e3a49ef33a Mon Sep 17 00:00:00 2001 From: reduz Date: Fri, 13 May 2022 15:04:37 +0200 Subject: Replace most uses of Map by HashMap * Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated! --- platform/linuxbsd/display_server_x11.cpp | 28 ++++++++++++++-------------- platform/linuxbsd/display_server_x11.h | 16 ++++++++-------- platform/linuxbsd/export/export_plugin.h | 2 +- platform/linuxbsd/tts_linux.h | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'platform/linuxbsd') diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 9f53b31567..5829711698 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -2360,10 +2360,10 @@ void DisplayServerX11::cursor_set_custom_image(const Ref &p_cursor, Cu _THREAD_SAFE_METHOD_ if (p_cursor.is_valid()) { - Map>::Element *cursor_c = cursors_cache.find(p_shape); + HashMap>::Iterator cursor_c = cursors_cache.find(p_shape); if (cursor_c) { - if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) { + if (cursor_c->value[0] == p_cursor && cursor_c->value[1] == p_hotspot) { cursor_set_shape(p_shape); return; } @@ -3456,9 +3456,9 @@ void DisplayServerX11::process_events() { } if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_PRESSURE)) { - Map::Element *pen_pressure = xi.pen_pressure_range.find(device_id); + HashMap::Iterator pen_pressure = xi.pen_pressure_range.find(device_id); if (pen_pressure) { - Vector2 pen_pressure_range = pen_pressure->value(); + Vector2 pen_pressure_range = pen_pressure->value; if (pen_pressure_range != Vector2()) { xi.pressure_supported = true; xi.pressure = (*values - pen_pressure_range[0]) / @@ -3470,9 +3470,9 @@ void DisplayServerX11::process_events() { } if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_TILTX)) { - Map::Element *pen_tilt_x = xi.pen_tilt_x_range.find(device_id); + HashMap::Iterator pen_tilt_x = xi.pen_tilt_x_range.find(device_id); if (pen_tilt_x) { - Vector2 pen_tilt_x_range = pen_tilt_x->value(); + Vector2 pen_tilt_x_range = pen_tilt_x->value; if (pen_tilt_x_range[0] != 0 && *values < 0) { xi.tilt.x = *values / -pen_tilt_x_range[0]; } else if (pen_tilt_x_range[1] != 0) { @@ -3484,9 +3484,9 @@ void DisplayServerX11::process_events() { } if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_TILTY)) { - Map::Element *pen_tilt_y = xi.pen_tilt_y_range.find(device_id); + HashMap::Iterator pen_tilt_y = xi.pen_tilt_y_range.find(device_id); if (pen_tilt_y) { - Vector2 pen_tilt_y_range = pen_tilt_y->value(); + Vector2 pen_tilt_y_range = pen_tilt_y->value; if (pen_tilt_y_range[0] != 0 && *values < 0) { xi.tilt.y = *values / -pen_tilt_y_range[0]; } else if (pen_tilt_y_range[1] != 0) { @@ -3508,11 +3508,11 @@ void DisplayServerX11::process_events() { xi.raw_pos.x = rel_x; xi.raw_pos.y = rel_y; - Map::Element *abs_info = xi.absolute_devices.find(device_id); + HashMap::Iterator abs_info = xi.absolute_devices.find(device_id); if (abs_info) { // Absolute mode device - Vector2 mult = abs_info->value(); + Vector2 mult = abs_info->value; xi.relative_motion.x += (xi.raw_pos.x - xi.old_raw_pos.x) * mult.x; xi.relative_motion.y += (xi.raw_pos.y - xi.old_raw_pos.y) * mult.y; @@ -3557,21 +3557,21 @@ void DisplayServerX11::process_events() { } break; case XI_TouchUpdate: { - Map::Element *curr_pos_elem = xi.state.find(index); + HashMap::Iterator curr_pos_elem = xi.state.find(index); if (!curr_pos_elem) { // Defensive break; } - if (curr_pos_elem->value() != pos) { + if (curr_pos_elem->value != pos) { Ref sd; sd.instantiate(); sd->set_window_id(window_id); sd->set_index(index); sd->set_position(pos); - sd->set_relative(pos - curr_pos_elem->value()); + sd->set_relative(pos - curr_pos_elem->value); Input::get_singleton()->parse_input_event(sd); - curr_pos_elem->value() = pos; + curr_pos_elem->value = pos; } } break; #endif diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index ee47d1a12c..66941fbe29 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -137,7 +137,7 @@ class DisplayServerX11 : public DisplayServer { Callable drop_files_callback; WindowID transient_parent = INVALID_WINDOW_ID; - Set transient_children; + RBSet transient_children; ObjectID instance_id; @@ -159,7 +159,7 @@ class DisplayServerX11 : public DisplayServer { unsigned int focus_order = 0; }; - Map windows; + HashMap windows; unsigned int last_mouse_monitor_mask = 0; Vector2i last_mouse_monitor_pos; @@ -197,12 +197,12 @@ class DisplayServerX11 : public DisplayServer { struct { int opcode; Vector touch_devices; - Map absolute_devices; - Map pen_pressure_range; - Map pen_tilt_x_range; - Map pen_tilt_y_range; + HashMap absolute_devices; + HashMap pen_pressure_range; + HashMap pen_tilt_x_range; + HashMap pen_tilt_y_range; XIEventMask all_event_mask; - Map state; + HashMap state; double pressure; bool pressure_supported; Vector2 tilt; @@ -241,7 +241,7 @@ class DisplayServerX11 : public DisplayServer { Cursor cursors[CURSOR_MAX]; Cursor null_cursor; CursorShape current_cursor = CURSOR_ARROW; - Map> cursors_cache; + HashMap> cursors_cache; bool layered_window = false; diff --git a/platform/linuxbsd/export/export_plugin.h b/platform/linuxbsd/export/export_plugin.h index f46fc68e1d..9ae5cf827a 100644 --- a/platform/linuxbsd/export/export_plugin.h +++ b/platform/linuxbsd/export/export_plugin.h @@ -38,7 +38,7 @@ #include "scene/resources/texture.h" class EditorExportPlatformLinuxBSD : public EditorExportPlatformPC { - Map extensions; + HashMap extensions; Error _export_debug_script(const Ref &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path); public: diff --git a/platform/linuxbsd/tts_linux.h b/platform/linuxbsd/tts_linux.h index 4d39af8970..4e3f348ae4 100644 --- a/platform/linuxbsd/tts_linux.h +++ b/platform/linuxbsd/tts_linux.h @@ -35,7 +35,7 @@ #include "core/os/thread_safe.h" #include "core/string/ustring.h" #include "core/templates/list.h" -#include "core/templates/map.h" +#include "core/templates/rb_map.h" #include "core/variant/array.h" #include "servers/display_server.h" @@ -49,7 +49,7 @@ class TTS_Linux { bool speaking = false; bool paused = false; int last_msg_id = -1; - Map ids; + HashMap ids; Thread init_thread; -- cgit v1.2.3