Skip to content

Commit 7490787

Browse files
committed
Merge pull request #103759 from Ivorforce/zero-constructible
Optimize `Array.resize` by using `memset` (through new `is_zero_constructible` type trait)
2 parents 1905749 + 75bc471 commit 7490787

File tree

19 files changed

+93
-11
lines changed

19 files changed

+93
-11
lines changed

core/math/aabb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,6 @@ AABB AABB::quantized(real_t p_unit) const {
495495
ret.quantize(p_unit);
496496
return ret;
497497
}
498+
499+
template <>
500+
struct is_zero_constructible<AABB> : std::true_type {};

core/math/audio_frame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,6 @@ _ALWAYS_INLINE_ AudioFrame operator*(int32_t p_scalar, const AudioFrame &p_frame
168168
_ALWAYS_INLINE_ AudioFrame operator*(int64_t p_scalar, const AudioFrame &p_frame) {
169169
return AudioFrame(p_frame.left * p_scalar, p_frame.right * p_scalar);
170170
}
171+
172+
template <>
173+
struct is_zero_constructible<AudioFrame> : std::true_type {};

core/math/face3.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,6 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
236236
}
237237
return true;
238238
}
239+
240+
template <>
241+
struct is_zero_constructible<Face3> : std::true_type {};

core/math/plane.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ bool Plane::operator==(const Plane &p_plane) const {
132132
bool Plane::operator!=(const Plane &p_plane) const {
133133
return normal != p_plane.normal || d != p_plane.d;
134134
}
135+
136+
template <>
137+
struct is_zero_constructible<Plane> : std::true_type {};

core/math/rect2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,6 @@ struct [[nodiscard]] Rect2 {
371371
size(p_size) {
372372
}
373373
};
374+
375+
template <>
376+
struct is_zero_constructible<Rect2> : std::true_type {};

core/math/rect2i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,6 @@ struct [[nodiscard]] Rect2i {
236236
size(p_size) {
237237
}
238238
};
239+
240+
template <>
241+
struct is_zero_constructible<Rect2i> : std::true_type {};

core/math/vector2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,6 @@ _FORCE_INLINE_ Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) {
326326

327327
typedef Vector2 Size2;
328328
typedef Vector2 Point2;
329+
330+
template <>
331+
struct is_zero_constructible<Vector2> : std::true_type {};

core/math/vector2i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,6 @@ _FORCE_INLINE_ Vector2i operator*(double p_scalar, const Vector2i &p_vector) {
168168

169169
typedef Vector2i Size2i;
170170
typedef Vector2i Point2i;
171+
172+
template <>
173+
struct is_zero_constructible<Vector2i> : std::true_type {};

core/math/vector3.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,6 @@ Vector3 Vector3::reflect(const Vector3 &p_normal) const {
549549
#endif
550550
return 2.0f * p_normal * dot(p_normal) - *this;
551551
}
552+
553+
template <>
554+
struct is_zero_constructible<Vector3> : std::true_type {};

core/math/vector3i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,6 @@ bool Vector3i::operator>=(const Vector3i &p_v) const {
334334
void Vector3i::zero() {
335335
x = y = z = 0;
336336
}
337+
338+
template <>
339+
struct is_zero_constructible<Vector3i> : std::true_type {};

0 commit comments

Comments
 (0)