Skip to content

Commit ef853bb

Browse files
committed
Merge pull request #111347 from Ivorforce/no-algorithm
Add `max()` to `Span`, replacing `<algorithm>` include from `rendering_device_commons.h`
2 parents 0f7bf29 + 1fa332c commit ef853bb

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

core/templates/span.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class Span {
108108
/// Note: Assumes that elements in the span are sorted. Otherwise, use find() instead.
109109
template <typename Comparator = Comparator<T>>
110110
constexpr uint64_t bisect(const T &p_value, bool p_before, Comparator compare = Comparator()) const;
111+
112+
/// The caller is responsible to ensure size() > 0.
113+
constexpr T max() const;
111114
};
112115

113116
template <typename T>
@@ -204,6 +207,18 @@ constexpr uint64_t Span<T>::bisect(const T &p_value, bool p_before, Comparator c
204207
return lo;
205208
}
206209

210+
template <typename T>
211+
constexpr T Span<T>::max() const {
212+
DEV_ASSERT(size() > 0);
213+
T max_val = _ptr[0];
214+
for (size_t i = 1; i < _len; ++i) {
215+
if (_ptr[i] > max_val) {
216+
max_val = _ptr[i];
217+
}
218+
}
219+
return max_val;
220+
}
221+
207222
// Zero-constructing Span initializes _ptr and _len to 0 (and thus empty).
208223
template <typename T>
209224
struct is_zero_constructible<Span<T>> : std::true_type {};

drivers/metal/metal_objects.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#import "rendering_shader_container_metal.h"
5757

5858
#import <os/signpost.h>
59+
#import <algorithm>
5960

6061
// We have to undefine these macros because they are defined in NSObjCRuntime.h.
6162
#undef MIN

servers/rendering/rendering_device_commons.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include "core/object/object.h"
3434
#include "core/variant/type_info.h"
3535

36-
#include <algorithm>
37-
3836
#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment) - 1)) / (m_alignment)) * (m_alignment))
3937

4038
// This may one day be used in Godot for interoperability between C arrays, Vector and LocalVector.

servers/rendering/rendering_device_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RenderingShaderContainerFormat;
7070
template <typename... RESOURCE_TYPES>
7171
struct VersatileResourceTemplate {
7272
static constexpr size_t RESOURCE_SIZES[] = { sizeof(RESOURCE_TYPES)... };
73-
static constexpr size_t MAX_RESOURCE_SIZE = std::max_element(RESOURCE_SIZES, RESOURCE_SIZES + sizeof...(RESOURCE_TYPES))[0];
73+
static constexpr size_t MAX_RESOURCE_SIZE = Span(RESOURCE_SIZES).max();
7474
uint8_t data[MAX_RESOURCE_SIZE];
7575

7676
template <typename T>

0 commit comments

Comments
 (0)