Skip to content

Commit e091206

Browse files
IvorforceWhalesState
authored andcommitted
Add contains_char() for single-character 'contains' calls.
1 parent 18f8a5c commit e091206

File tree

59 files changed

+106
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+106
-97
lines changed

core/debugger/remote_debugger_peer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ RemoteDebuggerPeer *RemoteDebuggerPeerTCP::create(const String &p_uri) {
223223
String debug_host = p_uri.replace("tcp://", "");
224224
uint16_t debug_port = 6007;
225225

226-
if (debug_host.contains(":")) {
226+
if (debug_host.contains_char(':')) {
227227
int sep_pos = debug_host.rfind_char(':');
228228
debug_port = debug_host.substr(sep_pos + 1).to_int();
229229
debug_host = debug_host.substr(0, sep_pos);

core/extension/extension_api_dump.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
12021202
if (F.name.begins_with("_")) {
12031203
continue; //hidden property
12041204
}
1205-
if (F.name.contains("/")) {
1205+
if (F.name.contains_char('/')) {
12061206
// Ignore properties with '/' (slash) in the name. These are only meant for use in the inspector.
12071207
continue;
12081208
}

core/io/file_access.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
741741
for (int i = 0; i < size; ++i) {
742742
String value = p_values[i];
743743

744-
if (value.contains("\"") || value.contains(p_delim) || value.contains("\n")) {
744+
if (value.contains_char('"') || value.contains(p_delim) || value.contains_char('\n')) {
745745
value = "\"" + value.replace("\"", "\"\"") + "\"";
746746
}
747747
if (i < size - 1) {

core/io/file_access_pack.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void PackedData::add_path(const String &p_pkg_path, const String &p_path, uint64
7171
// Search for directory.
7272
PackedDir *cd = root;
7373

74-
if (simplified_path.contains("/")) { // In a subdirectory.
74+
if (simplified_path.contains_char('/')) { // In a subdirectory.
7575
Vector<String> ds = simplified_path.get_base_dir().split("/");
7676

7777
for (int j = 0; j < ds.size(); j++) {
@@ -104,7 +104,7 @@ void PackedData::remove_path(const String &p_path) {
104104
// Search for directory.
105105
PackedDir *cd = root;
106106

107-
if (simplified_path.contains("/")) { // In a subdirectory.
107+
if (simplified_path.contains_char('/')) { // In a subdirectory.
108108
Vector<String> ds = simplified_path.get_base_dir().split("/");
109109

110110
for (int j = 0; j < ds.size(); j++) {

core/io/ip_address.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ IPAddress::IPAddress(const String &p_string) {
202202
// Wildcard (not a valid IP)
203203
wildcard = true;
204204

205-
} else if (p_string.contains(":")) {
205+
} else if (p_string.contains_char(':')) {
206206
// IPv6
207207
_parse_ipv6(p_string);
208208
valid = true;

core/object/class_db.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
11161116

11171117
String enum_name = p_enum;
11181118
if (!enum_name.is_empty()) {
1119-
if (enum_name.contains(".")) {
1119+
if (enum_name.contains_char('.')) {
11201120
enum_name = enum_name.get_slicec('.', 1);
11211121
}
11221122

core/string/ustring.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -3297,6 +3297,10 @@ int String::find(const String &p_str, int p_from) const {
32973297
return -1; // won't find anything!
32983298
}
32993299

3300+
if (src_len == 1) {
3301+
return find_char(p_str[0], p_from); // Optimize with single-char find.
3302+
}
3303+
33003304
const char32_t *src = get_data();
33013305
const char32_t *str = p_str.get_data();
33023306

@@ -3337,6 +3341,10 @@ int String::find(const char *p_str, int p_from) const {
33373341
return -1; // won't find anything!
33383342
}
33393343

3344+
if (src_len == 1) {
3345+
return find_char(*p_str, p_from); // Optimize with single-char find.
3346+
}
3347+
33403348
const char32_t *src = get_data();
33413349

33423350
if (src_len == 1) {
@@ -4060,7 +4068,7 @@ String String::format(const Variant &values, const String &placeholder) const {
40604068
Variant v_val = values_arr[i];
40614069
String val = v_val;
40624070

4063-
if (placeholder.contains("_")) {
4071+
if (placeholder.contains_char('_')) {
40644072
new_string = new_string.replace(placeholder.replace("_", i_as_str), val);
40654073
} else {
40664074
new_string = new_string.replace_first(placeholder, val);

core/string/ustring.h

+1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ class String {
432432
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
433433
_FORCE_INLINE_ bool contains(const char *p_str) const { return find(p_str) != -1; }
434434
_FORCE_INLINE_ bool contains(const String &p_str) const { return find(p_str) != -1; }
435+
_FORCE_INLINE_ bool contains_char(char32_t p_chr) const { return find_char(p_chr) != -1; }
435436
_FORCE_INLINE_ bool containsn(const char *p_str) const { return findn(p_str) != -1; }
436437
_FORCE_INLINE_ bool containsn(const String &p_str) const { return findn(p_str) != -1; }
437438

core/variant/variant_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
18211821
case Variant::FLOAT: {
18221822
String s = rtos_fix(p_variant.operator double());
18231823
if (s != "inf" && s != "inf_neg" && s != "nan") {
1824-
if (!s.contains(".") && !s.contains("e")) {
1824+
if (!s.contains_char('.') && !s.contains_char('e')) {
18251825
s += ".0";
18261826
}
18271827
}

drivers/unix/os_unix.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,13 @@ String OS_Unix::get_environment(const String &p_var) const {
907907
}
908908

909909
void OS_Unix::set_environment(const String &p_var, const String &p_value) const {
910-
ERR_FAIL_COND_MSG(p_var.is_empty() || p_var.contains("="), vformat("Invalid environment variable name '%s', cannot be empty or include '='.", p_var));
910+
ERR_FAIL_COND_MSG(p_var.is_empty() || p_var.contains_char('='), vformat("Invalid environment variable name '%s', cannot be empty or include '='.", p_var));
911911
int err = setenv(p_var.utf8().get_data(), p_value.utf8().get_data(), /* overwrite: */ 1);
912912
ERR_FAIL_COND_MSG(err != 0, vformat("Failed setting environment variable '%s', the system is out of memory.", p_var));
913913
}
914914

915915
void OS_Unix::unset_environment(const String &p_var) const {
916-
ERR_FAIL_COND_MSG(p_var.is_empty() || p_var.contains("="), vformat("Invalid environment variable name '%s', cannot be empty or include '='.", p_var));
916+
ERR_FAIL_COND_MSG(p_var.is_empty() || p_var.contains_char('='), vformat("Invalid environment variable name '%s', cannot be empty or include '='.", p_var));
917917
unsetenv(p_var.utf8().get_data());
918918
}
919919

editor/connections_dialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void ConnectDialog::set_dst_node(Node *p_node) {
524524

525525
StringName ConnectDialog::get_dst_method_name() const {
526526
String txt = dst_method->get_text();
527-
if (txt.contains("(")) {
527+
if (txt.contains_char('(')) {
528528
txt = txt.left(txt.find_char('(')).strip_edges();
529529
}
530530
return txt;

editor/debugger/debug_adapter/debug_adapter_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) co
359359
}
360360

361361
// If path contains \, it's a Windows path, so we need to convert it to /, and make the drive letter uppercase
362-
if (source.path.contains("\\")) {
362+
if (source.path.contains_char('\\')) {
363363
source.path = source.path.replace("\\", "/");
364364
source.path = source.path.substr(0, 1).to_upper() + source.path.substr(1);
365365
}

editor/debugger/debug_adapter/debug_adapter_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DebugAdapterParser : public Object {
4747

4848
_FORCE_INLINE_ bool is_valid_path(const String &p_path) const {
4949
// If path contains \, it's a Windows path, so we need to convert it to /, and check as case-insensitive.
50-
if (p_path.contains("\\")) {
50+
if (p_path.contains_char('\\')) {
5151
String project_path = ProjectSettings::get_singleton()->get_resource_path();
5252
String path = p_path.replace("\\", "/");
5353
return path.containsn(project_path);

editor/directory_create_dialog.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ String DirectoryCreateDialog::_validate_path(const String &p_path) const {
6767
return TTR("Folder name cannot be empty.");
6868
}
6969
}
70-
if (part.contains("\\") || part.contains(":") || part.contains("*") ||
71-
part.contains("|") || part.contains(">") || part.ends_with(".") || part.ends_with(" ")) {
70+
if (part.contains_char('\\') || part.contains_char(':') || part.contains_char('*') ||
71+
part.contains_char('|') || part.contains_char('>') || part.ends_with(".") || part.ends_with(" ")) {
7272
if (is_file) {
7373
return TTR("File name contains invalid characters.");
7474
} else {
@@ -101,7 +101,7 @@ void DirectoryCreateDialog::_on_dir_path_changed() {
101101
const String error = _validate_path(path);
102102

103103
if (error.is_empty()) {
104-
if (path.contains("/")) {
104+
if (path.contains_char('/')) {
105105
if (mode == MODE_DIRECTORY) {
106106
validation_panel->set_message(EditorValidationPanel::MSG_ID_DEFAULT, TTR("Using slashes in folder names will create subfolders recursively."), EditorValidationPanel::MSG_OK);
107107
} else {

editor/editor_feature_profile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void EditorFeatureProfileManager::_erase_selected_profile() {
475475

476476
void EditorFeatureProfileManager::_create_new_profile() {
477477
String name = new_profile_name->get_text().strip_edges();
478-
if (!name.is_valid_filename() || name.contains(".")) {
478+
if (!name.is_valid_filename() || name.contains_char('.')) {
479479
EditorNode::get_singleton()->show_warning(TTR("Profile must be a valid filename and must not contain '.'"));
480480
return;
481481
}

editor/editor_file_system.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void EditorFileSystem::_scan_filesystem() {
374374

375375
FileCache fc;
376376
fc.type = split[1];
377-
if (fc.type.contains("/")) {
377+
if (fc.type.contains_char('/')) {
378378
fc.type = split[1].get_slice("/", 0);
379379
fc.resource_script_class = split[1].get_slice("/", 1);
380380
}

editor/editor_help.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void EditorHelp::_class_desc_select(const String &p_select) {
326326
}
327327
}
328328

329-
if (link.contains(".")) {
329+
if (link.contains_char('.')) {
330330
const int class_end = link.find_char('.');
331331
emit_signal(SNAME("go_to_help"), topic + ":" + link.left(class_end) + ":" + link.substr(class_end + 1));
332332
}
@@ -371,7 +371,7 @@ static void _add_type_to_rt(const String &p_type, const String &p_enum, bool p_i
371371

372372
bool is_enum_type = !p_enum.is_empty();
373373
bool is_bitfield = p_is_bitfield && is_enum_type;
374-
bool can_ref = !p_type.contains("*") || is_enum_type;
374+
bool can_ref = !p_type.contains_char('*') || is_enum_type;
375375

376376
String link_t = p_type; // For links in metadata
377377
String display_t; // For display purposes.
@@ -2534,7 +2534,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
25342534
p_rt->push_meta("@" + link_tag + " " + link_target, underline_mode);
25352535

25362536
if (link_tag == "member" &&
2537-
((!link_target.contains(".") && (p_class == "ProjectSettings" || p_class == "EditorSettings")) ||
2537+
((!link_target.contains_char('.') && (p_class == "ProjectSettings" || p_class == "EditorSettings")) ||
25382538
link_target.begins_with("ProjectSettings.") || link_target.begins_with("EditorSettings."))) {
25392539
// Special formatting for both ProjectSettings and EditorSettings.
25402540
String prefix;
@@ -3652,7 +3652,7 @@ void EditorHelpBit::_meta_clicked(const String &p_select) {
36523652
return;
36533653
}
36543654

3655-
if (link.contains(".")) {
3655+
if (link.contains_char('.')) {
36563656
const int class_end = link.find_char('.');
36573657
_go_to_help(topic + ":" + link.left(class_end) + ":" + link.substr(class_end + 1));
36583658
} else {

editor/editor_inspector.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void EditorProperty::_notification(int p_what) {
288288
} else {
289289
color = get_theme_color(is_read_only() ? SNAME("readonly_color") : SNAME("property_color"));
290290
}
291-
if (label.contains(".")) {
291+
if (label.contains_char('.')) {
292292
// FIXME: Move this to the project settings editor, as this is only used
293293
// for project settings feature tag overrides.
294294
color.a = 0.5;
@@ -3190,7 +3190,7 @@ void EditorInspector::update_tree() {
31903190
}
31913191

31923192
// Get the property label's string.
3193-
String name_override = (path.contains("/")) ? path.substr(path.rfind_char('/') + 1) : path;
3193+
String name_override = (path.contains_char('/')) ? path.substr(path.rfind_char('/') + 1) : path;
31943194
String feature_tag;
31953195
{
31963196
const int dot = name_override.find_char('.');
@@ -3339,7 +3339,7 @@ void EditorInspector::update_tree() {
33393339
array_element_prefix = class_name_components[0];
33403340
editor_inspector_array = memnew(EditorInspectorArray(all_read_only));
33413341

3342-
String array_label = path.contains("/") ? path.substr(path.rfind_char('/') + 1) : path;
3342+
String array_label = path.contains_char('/') ? path.substr(path.rfind_char('/') + 1) : path;
33433343
array_label = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string, property_name_style, p.name, doc_name);
33443344
int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;
33453345
editor_inspector_array->setup_with_move_element_function(object, array_label, array_element_prefix, page, c, use_folding);

editor/editor_properties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ void EditorPropertyLayersGrid::_rename_operation_confirm() {
845845
if (new_name.length() == 0) {
846846
EditorNode::get_singleton()->show_warning(TTR("No name provided."));
847847
return;
848-
} else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) {
848+
} else if (new_name.contains_char('/') || new_name.contains_char('\\') || new_name.contains_char(':')) {
849849
EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
850850
return;
851851
}
@@ -2881,7 +2881,7 @@ void EditorPropertyNodePath::update_property() {
28812881
const Node *target_node = base_node->get_node(p);
28822882
ERR_FAIL_NULL(target_node);
28832883

2884-
if (String(target_node->get_name()).contains("@")) {
2884+
if (String(target_node->get_name()).contains_char('@')) {
28852885
assign->set_button_icon(Ref<Texture2D>());
28862886
assign->set_text(p);
28872887
return;

editor/editor_sectioned_inspector.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class SectionedInspectorFilter : public Object {
109109

110110
if (pi.name.begins_with(section + "/")) {
111111
pi.name = pi.name.replace_first(section + "/", "");
112-
if (!allow_sub && pi.name.contains("/")) {
112+
if (!allow_sub && pi.name.contains_char('/')) {
113113
continue;
114114
}
115115
p_list->push_back(pi);
@@ -248,7 +248,7 @@ void SectionedInspector::update_category_list() {
248248
continue;
249249
}
250250

251-
if (pi.name.contains(":") || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) {
251+
if (pi.name.contains_char(':') || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) {
252252
continue;
253253
}
254254

editor/filesystem_dock.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ void FileSystemDock::_rename_operation_confirm() {
18061806
if (new_name.length() == 0) {
18071807
EditorNode::get_singleton()->show_warning(TTR("No name provided."));
18081808
rename_error = true;
1809-
} else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) {
1809+
} else if (new_name.contains_char('/') || new_name.contains_char('\\') || new_name.contains_char(':')) {
18101810
EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
18111811
rename_error = true;
18121812
} else if (new_name[0] == '.') {
@@ -2269,7 +2269,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
22692269
test_args.push_back("command -v " + terminal_emulator);
22702270
const Error err = OS::get_singleton()->execute("bash", test_args, &pipe);
22712271
// Check if a path to the terminal executable exists.
2272-
if (err == OK && pipe.contains("/")) {
2272+
if (err == OK && pipe.contains_char('/')) {
22732273
chosen_terminal_emulator = terminal_emulator;
22742274
break;
22752275
} else if (err == ERR_CANT_FORK) {

editor/gui/scene_tree_editor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ bool SceneTreeEditor::_item_matches_all_terms(TreeItem *p_item, const PackedStri
741741
const String &term = p_terms[i];
742742

743743
// Recognize special filter.
744-
if (term.contains(":") && !term.get_slicec(':', 0).is_empty()) {
744+
if (term.contains_char(':') && !term.get_slicec(':', 0).is_empty()) {
745745
String parameter = term.get_slicec(':', 0);
746746
String argument = term.get_slicec(':', 1);
747747

editor/import/3d/collada.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1808,10 +1808,10 @@ void Collada::_parse_animation(XMLParser &p_parser) {
18081808
}
18091809
}
18101810

1811-
if (target.contains("/")) { //transform component
1811+
if (target.contains_char('/')) { //transform component
18121812
track.target = target.get_slicec('/', 0);
18131813
track.param = target.get_slicec('/', 1);
1814-
if (track.param.contains(".")) {
1814+
if (track.param.contains_char('.')) {
18151815
track.component = track.param.get_slice(".", 1).to_upper();
18161816
}
18171817
track.param = track.param.get_slice(".", 0);

editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void PostImportPluginSkeletonRestFixer::internal_process(InternalImportCategory
239239
List<StringName> anims;
240240
ap->get_animation_list(&anims);
241241
for (const StringName &name : anims) {
242-
if (String(name).contains("/")) {
242+
if (String(name).contains_char('/')) {
243243
continue; // Avoid animation library which may be created by importer dynamically.
244244
}
245245

editor/plugins/animation_blend_tree_editor_plugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
10751075

10761076
const String &new_name = p_text;
10771077

1078-
ERR_FAIL_COND(new_name.is_empty() || new_name.contains(".") || new_name.contains("/"));
1078+
ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
10791079

10801080
if (new_name == prev_name) {
10811081
return; //nothing to do

editor/plugins/animation_library_editor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void AnimationLibraryEditor::_item_renamed() {
475475
bool restore_text = false;
476476
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
477477

478-
if (String(text).contains("/") || String(text).contains(":") || String(text).contains(",") || String(text).contains("[")) {
478+
if (String(text).contains_char('/') || String(text).contains_char(':') || String(text).contains_char(',') || String(text).contains_char('[')) {
479479
restore_text = true;
480480
} else {
481481
if (ti->get_parent() == tree->get_root()) {

editor/plugins/animation_player_editor_plugin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void AnimationPlayerEditor::_animation_rename() {
514514
String selected_name = animation->get_item_text(selected);
515515

516516
// Remove library prefix if present.
517-
if (selected_name.contains("/")) {
517+
if (selected_name.contains_char('/')) {
518518
selected_name = selected_name.get_slice("/", 1);
519519
}
520520

@@ -547,7 +547,7 @@ void AnimationPlayerEditor::_animation_remove_confirmed() {
547547
ERR_FAIL_COND(al.is_null());
548548

549549
// For names of form lib_name/anim_name, remove library name prefix.
550-
if (current.contains("/")) {
550+
if (current.contains_char('/')) {
551551
current = current.get_slice("/", 1);
552552
}
553553
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
@@ -636,7 +636,7 @@ void AnimationPlayerEditor::_animation_name_edited() {
636636

637637
// Extract library prefix if present.
638638
String new_library_prefix = "";
639-
if (current.contains("/")) {
639+
if (current.contains_char('/')) {
640640
new_library_prefix = current.get_slice("/", 0) + "/";
641641
current = current.get_slice("/", 1);
642642
}
@@ -1359,7 +1359,7 @@ void AnimationPlayerEditor::_animation_duplicate() {
13591359
break;
13601360
}
13611361

1362-
if (new_name.contains("/")) {
1362+
if (new_name.contains_char('/')) {
13631363
// Discard library prefix.
13641364
new_name = new_name.get_slice("/", 1);
13651365
}

0 commit comments

Comments
 (0)