Merge pull request #104375 from YYF233333/is_empty

Replace `size() == 0` with `is_empty()`
This commit is contained in:
Thaddeus Crews 2025-04-02 07:37:31 -05:00
commit 9f222d500d
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
153 changed files with 316 additions and 316 deletions

View file

@ -1135,13 +1135,13 @@ CSGBrush *CSGMesh3D::_build_brush() {
Array arrays = mesh->surface_get_arrays(i);
if (arrays.size() == 0) {
if (arrays.is_empty()) {
_make_dirty();
ERR_FAIL_COND_V(arrays.is_empty(), memnew(CSGBrush));
}
Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX];
if (avertices.size() == 0) {
if (avertices.is_empty()) {
continue;
}
@ -1257,7 +1257,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
}
if (vertices.size() == 0) {
if (vertices.is_empty()) {
return memnew(CSGBrush);
}

View file

@ -379,7 +379,7 @@ void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<Vector3> faces = cs->get_brush_faces();
if (faces.size() == 0) {
if (faces.is_empty()) {
return;
}

View file

@ -1080,7 +1080,7 @@ Error FBXDocument::_parse_images(Ref<FBXState> p_state, const String &p_base_pat
}
// Fallback to loading as byte array.
data = FileAccess::get_file_as_bytes(path);
if (data.size() == 0) {
if (data.is_empty()) {
WARN_PRINT(vformat("FBX: Image index '%d' couldn't be loaded from path: %s because there was no data to load. Skipping it.", texture_i, path));
p_state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count.
p_state->source_images.push_back(Ref<Image>());

View file

@ -2846,7 +2846,7 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
while (subclass) {
if (subclass->extends_used) {
if (!subclass->extends_path.is_empty()) {
if (subclass->extends.size() == 0) {
if (subclass->extends.is_empty()) {
get_global_class_name(subclass->extends_path, r_base_type);
subclass = nullptr;
break;

View file

@ -2157,7 +2157,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
GDScriptParser::IdentifierNode *callee = static_cast<GDScriptParser::IdentifierNode *>(call->callee);
if (callee->name == "range") {
list_resolved = true;
if (call->arguments.size() < 1) {
if (call->arguments.is_empty()) {
push_error(R"*(Invalid call for "range()" function. Expected at least 1 argument, none given.)*", call->callee);
} else if (call->arguments.size() > 3) {
push_error(vformat(R"*(Invalid call for "range()" function. Expected at most 3 arguments, %d given.)*", call->arguments.size()), call->callee);

View file

@ -741,7 +741,7 @@ Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> p_state, const String &p_p
if (file.is_null()) {
return err;
}
if (buffer_data.size() == 0) {
if (buffer_data.is_empty()) {
return OK;
}
file->create(FileAccess::ACCESS_RESOURCES);
@ -773,7 +773,7 @@ Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> p_state, const String &p_
if (file.is_null()) {
return err;
}
if (buffer_data.size() == 0) {
if (buffer_data.is_empty()) {
return OK;
}
file->create(FileAccess::ACCESS_RESOURCES);
@ -1647,7 +1647,7 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTF
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state, const Vector<int32_t> p_attribs, const bool p_for_vertex, const bool p_for_vertex_indices) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 1;
@ -1712,7 +1712,7 @@ Vector<int> GLTFDocument::_decode_accessor_as_ints(Ref<GLTFState> p_state, const
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<int> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -1737,7 +1737,7 @@ Vector<float> GLTFDocument::_decode_accessor_as_floats(Ref<GLTFState> p_state, c
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<float> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -1768,7 +1768,7 @@ void GLTFDocument::_round_min_max_components(Vector<double> &r_type_min, Vector<
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state, const Vector<Vector2> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 2;
@ -1818,7 +1818,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state,
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
@ -1884,7 +1884,7 @@ void GLTFDocument::_calc_accessor_min_max(int p_i, const int p_element_count, Ve
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
@ -1938,7 +1938,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_sta
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
@ -1989,7 +1989,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_stat
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> p_state, const Vector<Quaternion> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 4;
@ -2045,7 +2045,7 @@ Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> p_state, c
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Vector2> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2068,7 +2068,7 @@ Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> p_state, c
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_state, const Vector<double> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 1;
@ -2117,7 +2117,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_stat
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 3;
@ -2167,7 +2167,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state,
}
GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const Vector<Vector3> p_reference_attribs, const float p_reference_multiplier, const bool p_for_vertex, const GLTFAccessorIndex p_reference_accessor) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
@ -2276,7 +2276,7 @@ GLTFAccessorIndex GLTFDocument::_encode_sparse_accessor_as_vec3(Ref<GLTFState> p
}
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> p_state, const Vector<Transform3D> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) {
if (p_attribs.is_empty()) {
return -1;
}
const int element_count = 16;
@ -2351,7 +2351,7 @@ Vector<Vector3> GLTFDocument::_decode_accessor_as_vec3(Ref<GLTFState> p_state, c
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Vector3> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2377,7 +2377,7 @@ Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> p_state, co
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Color> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2409,7 +2409,7 @@ Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> p
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Quaternion> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2428,7 +2428,7 @@ Vector<Transform2D> GLTFDocument::_decode_accessor_as_xform2d(Ref<GLTFState> p_s
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Transform2D> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2445,7 +2445,7 @@ Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> p_state, co
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Basis> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -2463,7 +2463,7 @@ Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> p_sta
const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex);
Vector<Transform3D> ret;
if (attribs.size() == 0) {
if (attribs.is_empty()) {
return ret;
}
@ -4148,7 +4148,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> p_state, const String &p_base_p
// Fallback to loading as byte array. This enables us to support the
// spec's requirement that we honor mimetype regardless of file URI.
data = FileAccess::get_file_as_bytes(resource_uri);
if (data.size() == 0) {
if (data.is_empty()) {
WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded as a buffer of MIME type '%s' from URI: %s because there was no data to load. Skipping it.", i, mime_type, resource_uri));
p_state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count.
p_state->source_images.push_back(Ref<Image>());

View file

@ -520,7 +520,7 @@ Error SkinTool::_determine_skeleton_roots(
skeleton->roots = roots;
if (roots.size() == 0) {
if (roots.is_empty()) {
return FAILED;
} else if (roots.size() == 1) {
return OK;

View file

@ -626,7 +626,7 @@ void GodotBody2D::integrate_velocities(real_t p_step) {
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0) {
if (contacts.is_empty() && linear_velocity == Vector2() && angular_velocity == 0) {
set_active(false); //stopped moving, deactivate
}
return;

View file

@ -665,7 +665,7 @@ bool GodotConcavePolygonShape2D::contains_point(const Vector2 &p_point) const {
}
bool GodotConcavePolygonShape2D::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const {
if (segments.size() == 0 || points.size() == 0) {
if (segments.is_empty() || points.is_empty()) {
return false;
}
@ -919,7 +919,7 @@ void GodotConcavePolygonShape2D::cull(const Rect2 &p_local_aabb, QueryCallback p
stack[i]=0;
*/
if (segments.size() == 0 || points.size() == 0 || bvh.size() == 0) {
if (segments.is_empty() || points.is_empty() || bvh.is_empty()) {
return;
}

View file

@ -701,7 +701,7 @@ void GodotBody3D::integrate_velocities(real_t p_step) {
if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3()) {
if (contacts.is_empty() && linear_velocity == Vector3() && angular_velocity == Vector3()) {
set_active(false); //stopped moving, deactivate
}

View file

@ -838,7 +838,7 @@ void GodotConvexPolygonShape3D::project_range(const Vector3 &p_normal, const Tra
Vector3 GodotConvexPolygonShape3D::get_support(const Vector3 &p_normal) const {
// Skip if there are no vertices in the mesh
if (mesh.vertices.size() == 0) {
if (mesh.vertices.is_empty()) {
return Vector3();
}
@ -1369,7 +1369,7 @@ void GodotConcavePolygonShape3D::_cull_segment(int p_idx, _SegmentCullParams *p_
}
bool GodotConcavePolygonShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const {
if (faces.size() == 0) {
if (faces.is_empty()) {
return false;
}
@ -1449,7 +1449,7 @@ bool GodotConcavePolygonShape3D::_cull(int p_idx, _CullParams *p_params) const {
void GodotConcavePolygonShape3D::cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata, bool p_invert_backface_collision) const {
// make matrix local to concave
if (faces.size() == 0) {
if (faces.is_empty()) {
return;
}

View file

@ -605,7 +605,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
g.multimesh_instances.clear();
if (g.cells.size() == 0) {
if (g.cells.is_empty()) {
//octant no longer needed
_octant_clean_up(p_key);
return true;
@ -637,7 +637,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
xform.basis = _ortho_bases[c.rot];
xform.set_origin(cellpos * cell_size + ofs);
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
if (baked_meshes.size() == 0) {
if (baked_meshes.is_empty()) {
if (mesh_library->get_item_mesh(c.item).is_valid()) {
if (!multimesh_items.has(c.item)) {
multimesh_items[c.item] = List<Pair<Transform3D, IndexKey>>();
@ -716,7 +716,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
//update multimeshes, only if not baked
if (baked_meshes.size() == 0) {
if (baked_meshes.is_empty()) {
for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) {
Octant::MultimeshInstance mmi;
@ -1642,7 +1642,7 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant
}
}
if (vertex_array.size() == 0) {
if (vertex_array.is_empty()) {
return;
}

View file

@ -115,7 +115,7 @@ void AudioStreamInteractiveTransitionEditor::_update_selection() {
filler_clip->set_disabled(selected.is_empty());
hold_previous->set_disabled(selected.is_empty());
if (selected.size() == 0) {
if (selected.is_empty()) {
return;
}

View file

@ -645,19 +645,19 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i
r_cluster_aabbs_buffer = rd->storage_buffer_create(cab.size(), cab);
Vector<uint8_t> lb = lights.to_byte_array();
if (lb.size() == 0) {
if (lb.is_empty()) {
lb.resize(sizeof(Light)); //even if no lights, the buffer must exist
}
lights_buffer = rd->storage_buffer_create(lb.size(), lb);
Vector<uint8_t> sb = seam_buffer_vec.to_byte_array();
if (sb.size() == 0) {
if (sb.is_empty()) {
sb.resize(sizeof(Vector2i) * 2); //even if no seams, the buffer must exist
}
seams_buffer = rd->storage_buffer_create(sb.size(), sb);
Vector<uint8_t> pb = p_probe_positions.to_byte_array();
if (pb.size() == 0) {
if (pb.is_empty()) {
pb.resize(sizeof(Probe));
}
probe_positions_buffer = rd->storage_buffer_create(pb.size(), pb);

View file

@ -650,7 +650,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
for (SelfList<CSharpScript> *elem = script_list.first(); elem; elem = elem->next()) {
// Do not reload scripts with only non-collectible instances to avoid disrupting event subscriptions and such.
bool is_reloadable = elem->self()->instances.size() == 0;
bool is_reloadable = elem->self()->instances.is_empty();
for (Object *obj : elem->self()->instances) {
ERR_CONTINUE(!obj->get_script_instance());
CSharpInstance *csi = static_cast<CSharpInstance *>(obj->get_script_instance());

View file

@ -249,7 +249,7 @@ String BindingsGenerator::bbcode_to_text(const String &p_bbcode, const TypeInter
const Vector<String> link_target_parts = link_target.split(".");
if (link_target_parts.size() <= 0 || link_target_parts.size() > 2) {
if (link_target_parts.is_empty() || link_target_parts.size() > 2) {
ERR_PRINT("Invalid reference format: '" + tag + "'.");
output.append(tag);
@ -561,7 +561,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
const Vector<String> link_target_parts = link_target.split(".");
if (link_target_parts.size() <= 0 || link_target_parts.size() > 2) {
if (link_target_parts.is_empty() || link_target_parts.size() > 2) {
ERR_PRINT("Invalid reference format: '" + tag + "'.");
xml_output.append("<c>");
@ -3200,7 +3200,7 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf
// Generate signal
{
bool is_parameterless = p_isignal.arguments.size() == 0;
bool is_parameterless = p_isignal.arguments.is_empty();
// Delegate name is [SignalName]EventHandler
String delegate_name = is_parameterless ? "Action" : p_isignal.proxy_name + "EventHandler";

View file

@ -376,7 +376,7 @@ Error MultiplayerSynchronizer::_watch_changes(uint64_t p_usec) {
if (props.size() != watchers.size()) {
watchers.resize(props.size());
}
if (props.size() == 0) {
if (props.is_empty()) {
return OK;
}
Node *node = get_root_node();

View file

@ -71,7 +71,7 @@ NavMeshGenerator2D::~NavMeshGenerator2D() {
}
void NavMeshGenerator2D::sync() {
if (generator_tasks.size() == 0) {
if (generator_tasks.is_empty()) {
return;
}

View file

@ -70,7 +70,7 @@ NavMeshGenerator3D::~NavMeshGenerator3D() {
}
void NavMeshGenerator3D::sync() {
if (generator_tasks.size() == 0) {
if (generator_tasks.is_empty()) {
return;
}

View file

@ -54,7 +54,7 @@ Vector<Ref<Image>> Noise::_get_seamless_image(int p_width, int p_height, int p_d
Ref<Image> Noise::get_seamless_image(int p_width, int p_height, bool p_invert, bool p_in_3d_space, real_t p_blend_skirt, bool p_normalize) const {
Vector<Ref<Image>> images = _get_seamless_image(p_width, p_height, 1, p_invert, p_in_3d_space, p_blend_skirt, p_normalize);
if (images.size() == 0) {
if (images.is_empty()) {
return Ref<Image>();
}
return images[0];

View file

@ -84,7 +84,7 @@ int OpenXRActionSet::get_action_count() const {
void OpenXRActionSet::clear_actions() {
// Actions held within our action set should be released and destroyed but just in case they are still used some where else
if (actions.size() == 0) {
if (actions.is_empty()) {
return;
}

View file

@ -69,7 +69,7 @@ String RegExMatch::get_subject() const {
}
int RegExMatch::get_group_count() const {
if (data.size() == 0) {
if (data.is_empty()) {
return 0;
}
return data.size() - 1;

View file

@ -285,7 +285,7 @@ Vector<uint8_t> save_exr_buffer(const Ref<Image> &p_img, bool p_grayscale) {
Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) {
const Vector<uint8_t> buffer = save_exr_buffer(p_img, p_grayscale);
if (buffer.size() == 0) {
if (buffer.is_empty()) {
print_error(String("Saving EXR failed."));
return ERR_FILE_CANT_WRITE;
} else {

View file

@ -64,7 +64,7 @@ bool WebRTCMultiplayerPeer::is_server() const {
}
void WebRTCMultiplayerPeer::poll() {
if (peer_map.size() == 0) {
if (peer_map.is_empty()) {
return;
}

View file

@ -451,7 +451,7 @@ bool WSLPeer::_verify_server_response() {
WSL_CHECK_NC("sec-websocket-accept", _compute_key_response(session_key));
#undef WSL_CHECK_NC
#undef WSL_CHECK
if (supported_protocols.size() == 0) {
if (supported_protocols.is_empty()) {
// We didn't request a custom protocol
ERR_FAIL_COND_V_MSG(headers.has("sec-websocket-protocol"), false, "Received unrequested sub-protocol -> " + headers["sec-websocket-protocol"]);
} else {

View file

@ -294,7 +294,7 @@ bool WebXRInterfaceJS::initialize() {
return false;
}
if (requested_reference_space_types.size() == 0) {
if (requested_reference_space_types.is_empty()) {
return false;
}