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:
@@ -97,7 +97,7 @@ public:
|
||||
|
||||
WindowID transient_parent = INVALID_WINDOW_ID;
|
||||
bool exclusive = false;
|
||||
Set<WindowID> transient_children;
|
||||
RBSet<WindowID> transient_children;
|
||||
|
||||
bool layered_window = false;
|
||||
bool fullscreen = false;
|
||||
@@ -125,7 +125,7 @@ private:
|
||||
|
||||
NSMenu *apple_menu = nullptr;
|
||||
NSMenu *dock_menu = nullptr;
|
||||
Map<String, NSMenu *> submenu;
|
||||
HashMap<String, NSMenu *> submenu;
|
||||
|
||||
struct WarpEvent {
|
||||
NSTimeInterval timestamp;
|
||||
@@ -167,9 +167,9 @@ private:
|
||||
|
||||
CursorShape cursor_shape = CURSOR_ARROW;
|
||||
NSCursor *cursors[CURSOR_MAX];
|
||||
Map<CursorShape, Vector<Variant>> cursors_cache;
|
||||
HashMap<CursorShape, Vector<Variant>> cursors_cache;
|
||||
|
||||
Map<WindowID, WindowData> windows;
|
||||
HashMap<WindowID, WindowData> windows;
|
||||
|
||||
const NSMenu *_get_menu_root(const String &p_menu_root) const;
|
||||
NSMenu *_get_menu_root(const String &p_menu_root);
|
||||
|
||||
@@ -1071,9 +1071,9 @@ String DisplayServerOSX::global_menu_get_item_submenu(const String &p_menu_root,
|
||||
if (menu_item) {
|
||||
const NSMenu *sub_menu = [menu_item submenu];
|
||||
if (sub_menu) {
|
||||
for (Map<String, NSMenu *>::Element *E = submenu.front(); E; E = E->next()) {
|
||||
if (E->get() == sub_menu) {
|
||||
return E->key();
|
||||
for (const KeyValue<String, NSMenu *> &E : submenu) {
|
||||
if (E.value == sub_menu) {
|
||||
return E.key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1901,8 +1901,8 @@ Vector<DisplayServer::WindowID> DisplayServerOSX::get_window_list() const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
Vector<int> ret;
|
||||
for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) {
|
||||
ret.push_back(E->key());
|
||||
for (const KeyValue<WindowID, WindowData> &E : windows) {
|
||||
ret.push_back(E.key);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -2468,8 +2468,8 @@ bool DisplayServerOSX::window_can_draw(WindowID p_window) const {
|
||||
bool DisplayServerOSX::can_any_window_draw() const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) {
|
||||
if (window_get_mode(E->key()) != WINDOW_MODE_MINIMIZED) {
|
||||
for (const KeyValue<WindowID, WindowData> &E : windows) {
|
||||
if (window_get_mode(E.key) != WINDOW_MODE_MINIMIZED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2505,9 +2505,9 @@ DisplayServer::WindowID DisplayServerOSX::get_window_at_screen_position(const Po
|
||||
position /= screen_get_max_scale();
|
||||
|
||||
NSInteger wnum = [NSWindow windowNumberAtPoint:NSMakePoint(position.x, position.y) belowWindowWithWindowNumber:0 /*topmost*/];
|
||||
for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) {
|
||||
if ([E->get().window_object windowNumber] == wnum) {
|
||||
return E->key();
|
||||
for (const KeyValue<WindowID, WindowData> &E : windows) {
|
||||
if ([E.value.window_object windowNumber] == wnum) {
|
||||
return E.key;
|
||||
}
|
||||
}
|
||||
return INVALID_WINDOW_ID;
|
||||
@@ -2678,10 +2678,10 @@ void DisplayServerOSX::cursor_set_custom_image(const Ref<Resource> &p_cursor, Cu
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
if (p_cursor.is_valid()) {
|
||||
Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
|
||||
HashMap<CursorShape, Vector<Variant>>::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;
|
||||
}
|
||||
@@ -2886,8 +2886,8 @@ void DisplayServerOSX::process_events() {
|
||||
Input::get_singleton()->flush_buffered_events();
|
||||
}
|
||||
|
||||
for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) {
|
||||
WindowData &wd = E->get();
|
||||
for (KeyValue<WindowID, WindowData> &E : windows) {
|
||||
WindowData &wd = E.value;
|
||||
if (wd.mpath.size() > 0) {
|
||||
update_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
|
||||
if (Geometry2D::is_point_in_polygon(wd.mouse_pos, wd.mpath)) {
|
||||
@@ -3266,11 +3266,11 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode
|
||||
|
||||
DisplayServerOSX::~DisplayServerOSX() {
|
||||
// Destroy all windows.
|
||||
for (Map<WindowID, WindowData>::Element *E = windows.front(); E;) {
|
||||
Map<WindowID, WindowData>::Element *F = E;
|
||||
E = E->next();
|
||||
[F->get().window_object setContentView:nil];
|
||||
[F->get().window_object close];
|
||||
for (HashMap<WindowID, WindowData>::Iterator E = windows.begin(); E;) {
|
||||
HashMap<WindowID, WindowData>::Iterator F = E;
|
||||
++E;
|
||||
[F->value.window_object setContentView:nil];
|
||||
[F->value.window_object close];
|
||||
}
|
||||
|
||||
// Destroy drivers.
|
||||
|
||||
@@ -51,7 +51,7 @@ void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset>
|
||||
r_features->push_back("64");
|
||||
}
|
||||
|
||||
bool EditorExportPlatformOSX::get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
|
||||
bool EditorExportPlatformOSX::get_export_option_visibility(const String &p_option, const HashMap<StringName, Variant> &p_options) const {
|
||||
// These options are not supported by built-in codesign, used on non macOS host.
|
||||
if (!OS::get_singleton()->has_feature("macos")) {
|
||||
if (p_option == "codesign/identity" || p_option == "codesign/timestamp" || p_option == "codesign/hardened_runtime" || p_option == "codesign/custom_options" || p_option.begins_with("notarization/")) {
|
||||
|
||||
@@ -101,7 +101,7 @@ class EditorExportPlatformOSX : public EditorExportPlatform {
|
||||
protected:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) 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;
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return "macOS"; }
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
r_features->push_back("macos");
|
||||
}
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) override {
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, RBSet<String> &p_features) override {
|
||||
}
|
||||
|
||||
EditorExportPlatformOSX();
|
||||
|
||||
@@ -140,10 +140,11 @@ size_t PListNode::get_asn1_size(uint8_t p_len_octets) const {
|
||||
} break;
|
||||
case PList::PLNodeType::PL_NODE_TYPE_DICT: {
|
||||
size_t size = 0;
|
||||
for (const Map<String, Ref<PListNode>>::Element *it = data_dict.front(); it; it = it->next()) {
|
||||
|
||||
for (const KeyValue<String, Ref<PListNode>> &E : data_dict) {
|
||||
size += 1 + _asn1_size_len(p_len_octets); // Sequence.
|
||||
size += 1 + _asn1_size_len(p_len_octets) + it->key().utf8().length(); //Key.
|
||||
size += 1 + _asn1_size_len(p_len_octets) + it->value()->get_asn1_size(p_len_octets); // Value.
|
||||
size += 1 + _asn1_size_len(p_len_octets) + E.key.utf8().length(); //Key.
|
||||
size += 1 + _asn1_size_len(p_len_octets) + E.value->get_asn1_size(p_len_octets); // Value.
|
||||
}
|
||||
return size;
|
||||
} break;
|
||||
@@ -225,13 +226,13 @@ bool PListNode::store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) cons
|
||||
case PList::PLNodeType::PL_NODE_TYPE_DICT: {
|
||||
p_stream.push_back(0x31); // Set.
|
||||
store_asn1_size(p_stream, p_len_octets);
|
||||
for (const Map<String, Ref<PListNode>>::Element *it = data_dict.front(); it; it = it->next()) {
|
||||
CharString cs = it->key().utf8();
|
||||
for (const KeyValue<String, Ref<PListNode>> &E : data_dict) {
|
||||
CharString cs = E.key.utf8();
|
||||
uint32_t size = cs.length();
|
||||
|
||||
// Sequence.
|
||||
p_stream.push_back(0x30);
|
||||
uint32_t seq_size = 2 * (1 + _asn1_size_len(p_len_octets)) + size + it->value()->get_asn1_size(p_len_octets);
|
||||
uint32_t seq_size = 2 * (1 + _asn1_size_len(p_len_octets)) + size + E.value->get_asn1_size(p_len_octets);
|
||||
if (p_len_octets > 1) {
|
||||
p_stream.push_back(0x80 + p_len_octets);
|
||||
}
|
||||
@@ -252,7 +253,7 @@ bool PListNode::store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) cons
|
||||
p_stream.push_back(cs[i]);
|
||||
}
|
||||
// Value.
|
||||
valid = valid && it->value()->store_asn1(p_stream, p_len_octets);
|
||||
valid = valid && E.value->store_asn1(p_stream, p_len_octets);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -317,12 +318,12 @@ void PListNode::store_text(String &p_stream, uint8_t p_indent) const {
|
||||
case PList::PLNodeType::PL_NODE_TYPE_DICT: {
|
||||
p_stream += String("\t").repeat(p_indent);
|
||||
p_stream += "<dict>\n";
|
||||
for (const Map<String, Ref<PListNode>>::Element *it = data_dict.front(); it; it = it->next()) {
|
||||
for (const KeyValue<String, Ref<PListNode>> &E : data_dict) {
|
||||
p_stream += String("\t").repeat(p_indent + 1);
|
||||
p_stream += "<key>";
|
||||
p_stream += it->key();
|
||||
p_stream += E.key;
|
||||
p_stream += "</key>\n";
|
||||
it->value()->store_text(p_stream, p_indent + 1);
|
||||
E.value->store_text(p_stream, p_indent + 1);
|
||||
}
|
||||
p_stream += String("\t").repeat(p_indent);
|
||||
p_stream += "</dict>\n";
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
|
||||
CharString data_string;
|
||||
Vector<Ref<PListNode>> data_array;
|
||||
Map<String, Ref<PListNode>> data_dict;
|
||||
HashMap<String, Ref<PListNode>> data_dict;
|
||||
union {
|
||||
int32_t data_int;
|
||||
bool data_bool;
|
||||
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
NSOpenGLContext *context = nullptr;
|
||||
};
|
||||
|
||||
Map<DisplayServer::WindowID, GLWindow> windows;
|
||||
RBMap<DisplayServer::WindowID, GLWindow> windows;
|
||||
|
||||
NSOpenGLContext *shared_context = nullptr;
|
||||
DisplayServer::WindowID current_window = DisplayServer::INVALID_WINDOW_ID;
|
||||
|
||||
@@ -167,8 +167,8 @@ void GLManager_OSX::make_current() {
|
||||
}
|
||||
|
||||
void GLManager_OSX::swap_buffers() {
|
||||
for (Map<DisplayServer::WindowID, GLWindow>::Element *E = windows.front(); E; E = E->next()) {
|
||||
[E->get().context flushBuffer];
|
||||
for (const KeyValue<DisplayServer::WindowID, GLWindow> &E : windows) {
|
||||
[E.value.context flushBuffer];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
@interface TTS_OSX : NSObject <AVSpeechSynthesizerDelegate> {
|
||||
// AVSpeechSynthesizer
|
||||
bool speaking;
|
||||
Map<id, int> ids;
|
||||
HashMap<id, int> ids;
|
||||
|
||||
// NSSpeechSynthesizer
|
||||
bool paused;
|
||||
|
||||
Reference in New Issue
Block a user