summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAnilforextra <anilforextra@gmail.com>2022-02-02 00:04:13 +0545
committerAnilforextra <anilforextra@gmail.com>2022-02-02 00:11:09 +0545
commitfc27636999a15f88b1f3b1d7101d84a67968ba06 (patch)
treee3b66fce3dfd70ef1e7d5a4d1543446af2deae47 /core
parentea12094f19b028c1dcf6d402b8cbb3296b2065a8 (diff)
Vectors: Use clear() and has().
Use clear() instead of resize(0). Use has() instead of "find(p_val) != -1".
Diffstat (limited to 'core')
-rw-r--r--core/debugger/remote_debugger_peer.cpp4
-rw-r--r--core/debugger/script_debugger.cpp2
-rw-r--r--core/io/compression.cpp6
-rw-r--r--core/io/packet_peer.cpp2
-rw-r--r--core/io/stream_peer.cpp4
-rw-r--r--core/math/convex_hull.cpp8
-rw-r--r--core/templates/vector.h4
7 files changed, 14 insertions, 16 deletions
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp
index a45430465f..715468489c 100644
--- a/core/debugger/remote_debugger_peer.cpp
+++ b/core/debugger/remote_debugger_peer.cpp
@@ -68,8 +68,8 @@ void RemoteDebuggerPeerTCP::close() {
running = false;
thread.wait_to_finish();
tcp_client->disconnect_from_host();
- out_buf.resize(0);
- in_buf.resize(0);
+ out_buf.clear();
+ in_buf.clear();
}
RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) {
diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp
index 36723e5568..4dd93249ef 100644
--- a/core/debugger/script_debugger.cpp
+++ b/core/debugger/script_debugger.cpp
@@ -104,7 +104,7 @@ void ScriptDebugger::send_error(const String &p_func, const String &p_file, int
// Store stack info, this is ugly, but allows us to separate EngineDebugger and ScriptDebugger. There might be a better way.
error_stack_info.append_array(p_stack_info);
EngineDebugger::get_singleton()->send_error(p_func, p_file, p_line, p_err, p_descr, p_editor_notify, p_type);
- error_stack_info.resize(0);
+ error_stack_info.clear();
}
Vector<ScriptLanguage::StackInfo> ScriptDebugger::get_error_stack_info() const {
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index d1f915f064..ae5ccf8354 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -212,7 +212,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
strm.avail_in = p_src_size;
// Ensure the destination buffer is empty
- p_dst_vect->resize(0);
+ p_dst_vect->clear();
// decompress until deflate stream ends or end of file
do {
@@ -244,7 +244,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
WARN_PRINT(strm.msg);
}
(void)inflateEnd(&strm);
- p_dst_vect->resize(0);
+ p_dst_vect->clear();
return ret;
}
} while (strm.avail_out > 0 && strm.avail_in > 0);
@@ -254,7 +254,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
// Enforce max output size
if (p_max_dst_size > -1 && strm.total_out > (uint64_t)p_max_dst_size) {
(void)inflateEnd(&strm);
- p_dst_vect->resize(0);
+ p_dst_vect->clear();
return Z_BUF_ERROR;
}
} while (ret != Z_STREAM_END);
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index e90d1695e5..0af236f766 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -39,7 +39,7 @@ void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes");
ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB");
encode_buffer_max_size = next_power_of_2(p_max_size);
- encode_buffer.resize(0);
+ encode_buffer.clear();
}
int PacketPeer::get_encode_buffer_max_size() const {
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 28ebe811c9..c65968ef03 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -98,7 +98,7 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
Error err = get_partial_data(&w[0], p_bytes, received);
if (err != OK) {
- data.resize(0);
+ data.clear();
} else if (received != data.size()) {
data.resize(received);
}
@@ -563,7 +563,7 @@ Vector<uint8_t> StreamPeerBuffer::get_data_array() const {
}
void StreamPeerBuffer::clear() {
- data.resize(0);
+ data.clear();
pointer = 0;
}
diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp
index 912ffb8b16..bd292f4c2a 100644
--- a/core/math/convex_hull.cpp
+++ b/core/math/convex_hull.cpp
@@ -2129,7 +2129,7 @@ bool ConvexHullInternal::shift_face(Face *p_face, real_t p_amount, LocalVector<V
printf("Needed %d iterations to remove part\n", n);
#endif
- p_stack.resize(0);
+ p_stack.clear();
p_face->origin = shifted_origin;
return true;
@@ -2167,9 +2167,9 @@ real_t ConvexHullComputer::compute(const Vector3 *p_coords, int32_t p_count, rea
return shift;
}
- vertices.resize(0);
- edges.resize(0);
- faces.resize(0);
+ vertices.clear();
+ edges.clear();
+ faces.clear();
LocalVector<ConvexHullInternal::Vertex *> old_vertices;
get_vertex_copy(hull.vertex_list, old_vertices);
diff --git a/core/templates/vector.h b/core/templates/vector.h
index bd4c6ade86..0877e04e01 100644
--- a/core/templates/vector.h
+++ b/core/templates/vector.h
@@ -95,9 +95,7 @@ public:
void append_array(Vector<T> p_other);
- bool has(const T &p_val) const {
- return find(p_val, 0) != -1;
- }
+ _FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }
template <class C>
void sort_custom() {