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!
This commit is contained in:
reduz 2022-05-13 15:04:37 +02:00 committed by Rémi Verschelde
parent 396def9b66
commit 746dddc067
587 changed files with 3707 additions and 3538 deletions

View file

@ -1501,7 +1501,7 @@ void DisplayServerWindows::cursor_set_custom_image(const Ref<Resource> &p_cursor
_THREAD_SAFE_METHOD_
if (p_cursor.is_valid()) {
Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
RBMap<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
@ -2006,7 +2006,7 @@ void DisplayServerWindows::_touch_event(WindowID p_window, bool p_pressed, float
}
void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, int idx) {
Map<int, Vector2>::Element *curr = touch_state.find(idx);
RBMap<int, Vector2>::Element *curr = touch_state.find(idx);
if (!curr) {
return;
}

View file

@ -314,7 +314,7 @@ class DisplayServerWindows : public DisplayServer {
RenderingDeviceVulkan *rendering_device_vulkan = nullptr;
#endif
Map<int, Vector2> touch_state;
RBMap<int, Vector2> touch_state;
int pressrc;
HINSTANCE hInstance; // Holds The Instance Of The Application
@ -389,7 +389,7 @@ class DisplayServerWindows : public DisplayServer {
Callable drop_files_callback;
WindowID transient_parent = INVALID_WINDOW_ID;
Set<WindowID> transient_children;
RBSet<WindowID> transient_children;
bool is_popup = false;
Rect2i parent_safe_rect;
@ -403,7 +403,7 @@ class DisplayServerWindows : public DisplayServer {
WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect);
WindowID window_id_counter = MAIN_WINDOW_ID;
Map<WindowID, WindowData> windows;
RBMap<WindowID, WindowData> windows;
WindowID last_focused_window = INVALID_WINDOW_ID;
@ -430,7 +430,7 @@ class DisplayServerWindows : public DisplayServer {
HCURSOR cursors[CURSOR_MAX] = { nullptr };
CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
Map<CursorShape, Vector<Variant>> cursors_cache;
RBMap<CursorShape, Vector<Variant>> cursors_cache;
void _drag_event(WindowID p_window, float p_x, float p_y, int idx);
void _touch_event(WindowID p_window, bool p_pressed, float p_x, float p_y, int idx);

View file

@ -106,7 +106,7 @@ List<String> EditorExportPlatformWindows::get_binary_extensions(const Ref<Editor
return list;
}
bool EditorExportPlatformWindows::get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
bool EditorExportPlatformWindows::get_export_option_visibility(const String &p_option, const HashMap<StringName, Variant> &p_options) const {
// This option is not supported by "osslsigncode", used on non-Windows host.
if (!OS::get_singleton()->has_feature("windows") && p_option == "codesign/identity_type") {
return false;

View file

@ -48,7 +48,7 @@ public:
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) override;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
virtual void get_export_options(List<ExportOption> *r_options) override;
virtual bool get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override;
virtual bool get_export_option_visibility(const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
virtual String get_template_file_name(const String &p_target, const String &p_arch) const override;
virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) const override;

View file

@ -67,7 +67,7 @@ private:
HGLRC hRC;
};
Map<DisplayServer::WindowID, GLWindow> _windows;
RBMap<DisplayServer::WindowID, GLWindow> _windows;
LocalVector<GLDisplay> _displays;
GLWindow *_current_window = nullptr;

View file

@ -178,7 +178,7 @@ void OS_Windows::initialize() {
// long as the windows scheduler resolution (~16-30ms) even for calls like Sleep(1)
timeBeginPeriod(1);
process_map = memnew((Map<ProcessID, ProcessInfo>));
process_map = memnew((HashMap<ProcessID, ProcessInfo>));
// Add current Godot PID to the list of known PIDs
ProcessInfo current_pi = {};

View file

@ -110,7 +110,7 @@ protected:
STARTUPINFO si;
PROCESS_INFORMATION pi;
};
Map<ProcessID, ProcessInfo> *process_map;
HashMap<ProcessID, ProcessInfo> *process_map;
public:
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override;

View file

@ -33,7 +33,7 @@
#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"
@ -54,7 +54,7 @@ class TTS_Windows {
int offset;
int id;
};
Map<ULONG, UTData> ids;
RBMap<ULONG, UTData> ids;
static void __stdcall speech_event_callback(WPARAM wParam, LPARAM lParam);
void _update_tts();