Skip to content

Commit

Permalink
Optimize string operations throughout the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed Dec 18, 2023
1 parent d76c1d0 commit d88ffbe
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 137 deletions.
4 changes: 2 additions & 2 deletions core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ Error DirAccess::make_dir_recursive(String p_dir) {
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
pos = full_dir.find("/", pos + 1);
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
base = full_dir.substr(0, pos + 1);
base = full_dir.left(pos + 1);
} else if (full_dir.begins_with("/")) {
base = "/";
} else if (full_dir.contains(":/")) {
base = full_dir.substr(0, full_dir.find(":/") + 2);
base = full_dir.left(full_dir.find(":/") + 2);
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
} while (qc % 2);

// Remove the extraneous newline we've added above.
line = line.substr(0, line.length() - 1);
line = line.left(-1);

Vector<String> strings;

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, uint32_t p_block_size) {
magic = p_magic.ascii().get_data();
magic = (magic + " ").substr(0, 4);
magic = magic.rpad(4, " ");

cmode = p_mode;
block_size = p_block_size;
Expand Down
6 changes: 3 additions & 3 deletions core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
}
}
}
return query.substr(1);
return query.right(-1);
}

Error HTTPClient::verify_headers(const Vector<String> &p_headers) {
Expand All @@ -117,8 +117,8 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
if (sp == -1) {
continue;
}
String key = s.substr(0, sp).strip_edges();
String value = s.substr(sp + 1, s.length()).strip_edges();
String key = s.left(sp).strip_edges();
String value = s.substr(sp + 1).strip_edges();
ret[key] = value;
}

Expand Down
2 changes: 1 addition & 1 deletion core/string/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ NodePath::NodePath(const String &p_path) {
}
}

path = path.substr(0, subpath_pos);
path = path.left(subpath_pos);
}

for (int i = (int)absolute; i < path.length(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions core/string/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,9 @@ void TranslationServer::_bind_methods() {

void TranslationServer::load_translations() {
_load_translations("internationalization/locale/translations"); //all
_load_translations("internationalization/locale/translations_" + locale.substr(0, 2));
_load_translations("internationalization/locale/translations_" + locale.left(2));

if (locale.substr(0, 2) != locale) {
if (locale.left(2) != locale) {
_load_translations("internationalization/locale/translations_" + locale);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/string/translation_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ void TranslationPO::_cache_plural_tests(const String &p_plural_rule) {
return;
}

String equi_test = p_plural_rule.substr(0, first_ques_mark).strip_edges();
String equi_test = p_plural_rule.left(first_ques_mark).strip_edges();
equi_tests.push_back(equi_test);

String after_colon = p_plural_rule.substr(p_plural_rule.find(":") + 1, p_plural_rule.length());
String after_colon = p_plural_rule.substr(p_plural_rule.find(":") + 1);
_cache_plural_tests(after_colon);
}

Expand Down
Loading

0 comments on commit d88ffbe

Please sign in to comment.