mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
Reduce and prevent unnecessary random-access to List
Random-access access to `List` when iterating is `O(n^2)` (`O(n)` when accessing a single element) * Removed subscript operator, in favor of a more explicit `get` * Added conversion from `Iterator` to `ConstIterator` * Remade existing operations into other solutions when applicable
This commit is contained in:
@@ -93,8 +93,8 @@ void EditorTranslationParser::get_recognized_extensions(List<String> *r_extensio
|
||||
custom_parsers[i]->get_recognized_extensions(&temp);
|
||||
}
|
||||
// Remove duplicates.
|
||||
for (int i = 0; i < temp.size(); i++) {
|
||||
extensions.insert(temp[i]);
|
||||
for (const String &E : temp) {
|
||||
extensions.insert(E);
|
||||
}
|
||||
for (const String &E : extensions) {
|
||||
r_extensions->push_back(E);
|
||||
@@ -104,8 +104,8 @@ void EditorTranslationParser::get_recognized_extensions(List<String> *r_extensio
|
||||
bool EditorTranslationParser::can_parse(const String &p_extension) const {
|
||||
List<String> extensions;
|
||||
get_recognized_extensions(&extensions);
|
||||
for (int i = 0; i < extensions.size(); i++) {
|
||||
if (p_extension == extensions[i]) {
|
||||
for (const String &extension : extensions) {
|
||||
if (p_extension == extension) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -117,8 +117,8 @@ Ref<EditorTranslationParserPlugin> EditorTranslationParser::get_parser(const Str
|
||||
for (int i = 0; i < custom_parsers.size(); i++) {
|
||||
List<String> temp;
|
||||
custom_parsers[i]->get_recognized_extensions(&temp);
|
||||
for (int j = 0; j < temp.size(); j++) {
|
||||
if (temp[j] == p_extension) {
|
||||
for (const String &E : temp) {
|
||||
if (E == p_extension) {
|
||||
return custom_parsers[i];
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,8 @@ Ref<EditorTranslationParserPlugin> EditorTranslationParser::get_parser(const Str
|
||||
for (int i = 0; i < standard_parsers.size(); i++) {
|
||||
List<String> temp;
|
||||
standard_parsers[i]->get_recognized_extensions(&temp);
|
||||
for (int j = 0; j < temp.size(); j++) {
|
||||
if (temp[j] == p_extension) {
|
||||
for (const String &E : temp) {
|
||||
if (E == p_extension) {
|
||||
return standard_parsers[i];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user