summaryrefslogtreecommitdiff
path: root/editor/debugger/debug_adapter
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-05-13 15:04:37 +0200
committerRĂ©mi Verschelde <rverschelde@gmail.com>2022-05-16 10:37:48 +0200
commit746dddc0673d7261f19b1e056e90e6e3a49ef33a (patch)
tree434b526eb286850ebccc6d2c998a7d90fdb8b5e2 /editor/debugger/debug_adapter
parent396def9b66c476f7834604adb7136ca903ed01be (diff)
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!
Diffstat (limited to 'editor/debugger/debug_adapter')
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_parser.cpp14
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_protocol.cpp8
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_protocol.h4
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_types.h7
4 files changed, 18 insertions, 15 deletions
diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
index e7baeeeded..0caeb90108 100644
--- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp
+++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
@@ -381,12 +381,12 @@ Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
DAP::StackFrame frame;
frame.id = frame_id;
- Map<DAP::StackFrame, List<int>>::Element *E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame);
+ HashMap<DAP::StackFrame, List<int>, DAP::StackFrame>::Iterator E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame);
if (E) {
- ERR_FAIL_COND_V(E->value().size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
+ ERR_FAIL_COND_V(E->value.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
for (int i = 0; i < 3; i++) {
DAP::Scope scope;
- scope.variablesReference = E->value()[i];
+ scope.variablesReference = E->value[i];
switch (i) {
case 0:
scope.name = "Locals";
@@ -424,16 +424,16 @@ Dictionary DebugAdapterParser::req_variables(const Dictionary &p_params) const {
Dictionary args = p_params["arguments"];
int variable_id = args["variablesReference"];
- Map<int, Array>::Element *E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id);
+ HashMap<int, Array>::Iterator E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id);
if (E) {
if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsVariableType) {
- for (int i = 0; i < E->value().size(); i++) {
- Dictionary variable = E->value()[i];
+ for (int i = 0; i < E->value.size(); i++) {
+ Dictionary variable = E->value[i];
variable.erase("type");
}
}
- body["variables"] = E ? E->value() : Array();
+ body["variables"] = E ? E->value : Array();
return response;
} else {
return Dictionary();
diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
index fea4c2b156..92ea0f15e9 100644
--- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
+++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
@@ -918,11 +918,11 @@ void DebugAdapterProtocol::on_debug_stack_frame_vars(const int &p_size) {
DAP::StackFrame frame;
frame.id = _current_frame;
ERR_FAIL_COND(!stackframe_list.has(frame));
- List<int> scope_ids = stackframe_list.find(frame)->value();
+ List<int> scope_ids = stackframe_list.find(frame)->value;
for (List<int>::Element *E = scope_ids.front(); E; E = E->next()) {
int variable_id = E->get();
if (variable_list.has(variable_id)) {
- variable_list.find(variable_id)->value().clear();
+ variable_list.find(variable_id)->value.clear();
} else {
variable_list.insert(variable_id, Array());
}
@@ -937,7 +937,7 @@ void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) {
DAP::StackFrame frame;
frame.id = _current_frame;
- List<int> scope_ids = stackframe_list.find(frame)->value();
+ List<int> scope_ids = stackframe_list.find(frame)->value;
ERR_FAIL_COND(scope_ids.size() != 3);
ERR_FAIL_INDEX(stack_var.type, 3);
int variable_id = scope_ids[stack_var.type];
@@ -949,7 +949,7 @@ void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) {
variable.type = Variant::get_type_name(stack_var.value.get_type());
variable.variablesReference = parse_variant(stack_var.value);
- variable_list.find(variable_id)->value().push_back(variable.to_json());
+ variable_list.find(variable_id)->value.push_back(variable.to_json());
_remaining_vars--;
}
diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.h b/editor/debugger/debug_adapter/debug_adapter_protocol.h
index 66db75c634..a17e550dfc 100644
--- a/editor/debugger/debug_adapter/debug_adapter_protocol.h
+++ b/editor/debugger/debug_adapter/debug_adapter_protocol.h
@@ -115,8 +115,8 @@ private:
int stackframe_id = 0;
int variable_id = 0;
List<DAP::Breakpoint> breakpoint_list;
- Map<DAP::StackFrame, List<int>> stackframe_list;
- Map<int, Array> variable_list;
+ HashMap<DAP::StackFrame, List<int>, DAP::StackFrame> stackframe_list;
+ HashMap<int, Array> variable_list;
public:
friend class DebugAdapterServer;
diff --git a/editor/debugger/debug_adapter/debug_adapter_types.h b/editor/debugger/debug_adapter/debug_adapter_types.h
index 77b70909b3..4d77b6d51c 100644
--- a/editor/debugger/debug_adapter/debug_adapter_types.h
+++ b/editor/debugger/debug_adapter/debug_adapter_types.h
@@ -219,8 +219,11 @@ struct StackFrame {
int line;
int column;
- bool operator<(const StackFrame &p_other) const {
- return id < p_other.id;
+ static uint32_t hash(const StackFrame &p_frame) {
+ return hash_djb2_one_32(p_frame.id);
+ }
+ bool operator==(const StackFrame &p_other) const {
+ return id == p_other.id;
}
_FORCE_INLINE_ void from_json(const Dictionary &p_params) {