Skip to content

Commit a0060b6

Browse files
neildharfacebook-github-bot
authored andcommitted
Use std::min/max
Summary: std::min/max in C++14 is constexpr. Reviewed By: dulinriley Differential Revision: D26495307 fbshipit-source-id: 38a5c415beff883cb3738cae7b4e24061993f17d
1 parent fb7a248 commit a0060b6

9 files changed

Lines changed: 13 additions & 23 deletions

File tree

include/hermes/Support/Algorithms.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ ForwardIt uninitializedCopyN(InputIt src, Size count, ForwardIt dst) {
4242
return std::uninitialized_copy_n(src, count, dst);
4343
}
4444

45-
/// std::min and std::max are only made constexpr in C++14.
46-
template <class T>
47-
constexpr const T &max(const T &a, const T &b) {
48-
return a < b ? b : a;
49-
}
50-
51-
template <class T>
52-
constexpr const T &min(const T &a, const T &b) {
53-
return b < a ? b : a;
54-
}
55-
5645
} // namespace hermes
5746

5847
#endif // HERMES_SUPPORT_ALGORITHMS_H

include/hermes/VM/GCBase-inline.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,19 @@ T *GCBase::makeA(uint32_t size, Args &&...args) {
8585
#ifdef HERMESVM_GC_RUNTIME
8686
constexpr uint32_t GCBase::maxAllocationSizeImpl() {
8787
// Return the lesser of the two GC options' max allowed sizes.
88-
return min(HadesGC::maxAllocationSizeImpl(), GenGC::maxAllocationSizeImpl());
88+
return std::min(
89+
HadesGC::maxAllocationSizeImpl(), GenGC::maxAllocationSizeImpl());
8990
}
9091

9192
constexpr uint32_t GCBase::minAllocationSizeImpl() {
9293
// Return the greater of the two GC options' min allowed sizes.
93-
return max(HadesGC::minAllocationSizeImpl(), GenGC::minAllocationSizeImpl());
94+
return std::max(
95+
HadesGC::minAllocationSizeImpl(), GenGC::minAllocationSizeImpl());
9496
}
9597
#endif
9698

9799
constexpr uint32_t GCBase::maxAllocationSize() {
98-
return min(GC::maxAllocationSizeImpl(), GCCell::maxSize());
100+
return std::min(GC::maxAllocationSizeImpl(), GCCell::maxSize());
99101
}
100102

101103
constexpr uint32_t GCBase::minAllocationSize() {

include/hermes/VM/GCCell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class KindAndSize {
6363
// On 64 bit platforms without compressed pointers, just make the size 32 bits
6464
// so that it can be accessed without any masking or shifting.
6565
static constexpr size_t kNumSizeBits =
66-
min<size_t>(kNumBits - kNumKindBits, 32);
66+
std::min<size_t>(kNumBits - kNumKindBits, 32);
6767
static_assert(
6868
kNumCellKinds < 256,
6969
"More cell kinds than available kind bits.");

include/hermes/VM/HadesGC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class HadesGC final : public GCBase {
8585

8686
static constexpr uint32_t minAllocationSizeImpl() {
8787
return heapAlignSize(
88-
max(sizeof(OldGen::FreelistCell), sizeof(CopyListCell)));
88+
std::max(sizeof(OldGen::FreelistCell), sizeof(CopyListCell)));
8989
}
9090

9191
/// \name GCBase overrides

include/hermes/VM/OrderedHashMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class OrderedHashMap final : public GCCell {
164164
// It needs to be less than 1/4th the max 32-bit integer in order to use an
165165
// integer-based load factor check of 0.75.
166166
static constexpr uint32_t MAX_CAPACITY =
167-
min(ArrayStorageSmall::maxElements(), UINT32_MAX / 4);
167+
std::min(ArrayStorageSmall::maxElements(), UINT32_MAX / 4);
168168

169169
/// Capacity of the hash table.
170170
uint32_t capacity_{INITIAL_CAPACITY};

include/hermes/VM/SegmentedArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ constexpr SegmentedArray::SegmentNumber SegmentedArray::maxNumSegments() {
603603
slotCapacityForAllocationSize(GC::maxAllocationSize());
604604
const SegmentedArray::SegmentNumber maxAllocSegments =
605605
maxAllocSlots - kValueToSegmentThreshold;
606-
return min(maxAllocSegments, maxNumSegmentsWithoutOverflow());
606+
return std::min(maxAllocSegments, maxNumSegmentsWithoutOverflow());
607607
}
608608

609609
constexpr SegmentedArray::SegmentNumber

include/hermes/VM/SmallHermesValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class HermesValue32 {
168168
/// turned off on a 64-bit platform (e.g. with MallocGC) since we would end up
169169
/// using HermesValue32, but RawType would be 64 bits.
170170
static constexpr size_t kNumSmiBits =
171-
min(kNumValueBits, static_cast<size_t>(54));
171+
std::min(kNumValueBits, static_cast<size_t>(54));
172172

173173
/// A 3 bit tag describing the stored value. Tags that represent multiple
174174
/// types are distinguished using an additional bit found in the "ETag".

include/hermes/VM/StringPrimitive.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ class StringPrimitive : public VariableSizeRuntimeCell {
133133
/// Concatenation resulting in this size or larger will use
134134
/// BufferedStringPrimitive. We want to ensure that they satisfy the
135135
/// requirements for external strings.
136-
/// NOTE: we want to use std::max(256, EXTERNAL_STRING_MIN_SIZE) here, but it
137-
/// is not constexpr yet in C++11.
138136
static constexpr uint32_t CONCAT_STRING_MIN_SIZE =
139-
256 > EXTERNAL_STRING_MIN_SIZE ? 256 : EXTERNAL_STRING_MIN_SIZE;
137+
std::max(256u, EXTERNAL_STRING_MIN_SIZE);
140138

141139
static bool classof(const GCCell *cell) {
142140
return kindInRange(

lib/VM/gcs/GenGCNC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ using uintegral = typename std::enable_if<
243243
/// Otherwise return 0.
244244
template <typename T>
245245
constexpr int doubleDigitsDiff() {
246-
return max(std::numeric_limits<T>::digits,
246+
return std::max(
247+
std::numeric_limits<T>::digits,
247248
std::numeric_limits<double>::digits) -
248249
std::numeric_limits<double>::digits;
249250
}

0 commit comments

Comments
 (0)