mirror of https://github.com/godotengine/godot
Optimize is_valid_filename and validate_filename by caching invalid filename characters, instead of re-splitting each call.
This commit is contained in:
parent
0f20e67d8d
commit
0d2e13bcb8
|
|
@ -5286,7 +5286,7 @@ bool String::is_valid_html_color() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes made to the set of invalid filename characters must also be reflected in the String documentation for is_valid_filename.
|
// Changes made to the set of invalid filename characters must also be reflected in the String documentation for is_valid_filename.
|
||||||
static const char *invalid_filename_characters = ": / \\ ? * \" | % < >";
|
static const char *invalid_filename_characters[] = { ":", "/", "\\", "?", "*", "\"", "|", "%", "<", ">" };
|
||||||
|
|
||||||
bool String::is_valid_filename() const {
|
bool String::is_valid_filename() const {
|
||||||
String stripped = strip_edges();
|
String stripped = strip_edges();
|
||||||
|
|
@ -5298,8 +5298,7 @@ bool String::is_valid_filename() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> chars = String(invalid_filename_characters).split(" ");
|
for (const char *ch : invalid_filename_characters) {
|
||||||
for (const String &ch : chars) {
|
|
||||||
if (contains(ch)) {
|
if (contains(ch)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -5308,10 +5307,9 @@ bool String::is_valid_filename() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::validate_filename() const {
|
String String::validate_filename() const {
|
||||||
Vector<String> chars = String(invalid_filename_characters).split(" ");
|
|
||||||
String name = strip_edges();
|
String name = strip_edges();
|
||||||
for (int i = 0; i < chars.size(); i++) {
|
for (const char *ch : invalid_filename_characters) {
|
||||||
name = name.replace(chars[i], "_");
|
name = name.replace(ch, "_");
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue