3939
4040void InputMap::_bind_methods () {
4141 ClassDB::bind_method (D_METHOD (" has_action" , " action" ), &InputMap::has_action);
42- ClassDB::bind_method (D_METHOD (" get_actions" ), &InputMap::_get_actions );
42+ ClassDB::bind_method (D_METHOD (" get_actions" ), &InputMap::get_actions );
4343 ClassDB::bind_method (D_METHOD (" add_action" , " action" , " deadzone" ), &InputMap::add_action, DEFVAL (DEFAULT_DEADZONE));
4444 ClassDB::bind_method (D_METHOD (" erase_action" , " action" ), &InputMap::erase_action);
4545
@@ -61,16 +61,15 @@ void InputMap::_bind_methods() {
6161 * matching action name (if possible).
6262 */
6363String InputMap::suggest_actions (const StringName &p_action) const {
64- List<StringName> actions = get_actions ();
6564 StringName closest_action;
6665 float closest_similarity = 0.0 ;
6766
6867 // Find the most action with the most similar name.
69- for (const StringName &action : actions ) {
70- const float similarity = String (action ).similarity (p_action);
68+ for (const KeyValue< StringName, Action> &kv : input_map ) {
69+ const float similarity = String (kv. key ).similarity (p_action);
7170
7271 if (similarity > closest_similarity) {
73- closest_action = action ;
72+ closest_action = kv. key ;
7473 closest_similarity = similarity;
7574 }
7675 }
@@ -128,31 +127,18 @@ void InputMap::erase_action(const StringName &p_action) {
128127 input_map.erase (p_action);
129128}
130129
131- TypedArray<StringName> InputMap::_get_actions () {
130+ TypedArray<StringName> InputMap::get_actions () {
132131 TypedArray<StringName> ret;
133- List<StringName> actions = get_actions ();
134- if (actions.is_empty ()) {
135- return ret;
136- }
137-
138- for (const StringName &E : actions) {
139- ret.push_back (E);
140- }
141132
142- return ret;
143- }
133+ ret.resize (input_map.size ());
144134
145- List<StringName> InputMap::get_actions () const {
146- List<StringName> actions = List<StringName>();
147- if (input_map.is_empty ()) {
148- return actions;
149- }
150-
151- for (const KeyValue<StringName, Action> &E : input_map) {
152- actions.push_back (E.key );
135+ uint32_t i = 0 ;
136+ for (const KeyValue<StringName, Action> &kv : input_map) {
137+ ret[i] = kv.key ;
138+ i++;
153139 }
154140
155- return actions ;
141+ return ret ;
156142}
157143
158144List<Ref<InputEvent>>::Element *InputMap::_find_event (Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {
0 commit comments