Skip to content

Commit de05159

Browse files
authored
Merge pull request ceph#52293 from ronen-fr/wip-rf-consttime
common: make some common ctors and accessors constexpr Reviewed-by: Matan Breizman <[email protected]>
2 parents 58df861 + 540d4ec commit de05159

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/include/byteorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ceph_le {
2424
v = boost::endian::native_to_little(nv);
2525
return *this;
2626
}
27-
operator T() const { return boost::endian::little_to_native(v); }
27+
constexpr operator T() const { return boost::endian::little_to_native(v); }
2828
friend inline bool operator==(ceph_le a, ceph_le b) {
2929
return a.v == b.v;
3030
}

src/include/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ struct shard_id_t {
503503
int8_t id;
504504

505505
shard_id_t() : id(0) {}
506-
explicit shard_id_t(int8_t _id) : id(_id) {}
506+
constexpr explicit shard_id_t(int8_t _id) : id(_id) {}
507507

508508
operator int8_t() const { return id; }
509509

src/include/utime.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ class utime_t {
5656
return (tv.tv_sec == 0) && (tv.tv_nsec == 0);
5757
}
5858

59-
void normalize() {
59+
constexpr void normalize() {
6060
if (tv.tv_nsec > 1000000000ul) {
6161
tv.tv_sec = cap_to_u32_max(tv.tv_sec + tv.tv_nsec / (1000000000ul));
6262
tv.tv_nsec %= 1000000000ul;
6363
}
6464
}
6565

6666
// cons
67-
utime_t() { tv.tv_sec = 0; tv.tv_nsec = 0; }
68-
utime_t(time_t s, int n) { tv.tv_sec = s; tv.tv_nsec = n; normalize(); }
69-
utime_t(const struct ceph_timespec &v) {
67+
constexpr utime_t() { tv.tv_sec = 0; tv.tv_nsec = 0; }
68+
constexpr utime_t(time_t s, int n) { tv.tv_sec = s; tv.tv_nsec = n; normalize(); }
69+
constexpr utime_t(const struct ceph_timespec &v) {
7070
decode_timeval(&v);
7171
}
72-
utime_t(const struct timespec v)
72+
constexpr utime_t(const struct timespec v)
7373
{
7474
// NOTE: this is used by ceph_clock_now() so should be kept
7575
// as thin as possible.
@@ -125,9 +125,9 @@ class utime_t {
125125
}
126126

127127
// accessors
128-
time_t sec() const { return tv.tv_sec; }
129-
long usec() const { return tv.tv_nsec/1000; }
130-
int nsec() const { return tv.tv_nsec; }
128+
constexpr time_t sec() const { return tv.tv_sec; }
129+
constexpr long usec() const { return tv.tv_nsec/1000; }
130+
constexpr int nsec() const { return tv.tv_nsec; }
131131

132132
// ref accessors/modifiers
133133
__u32& sec_ref() { return tv.tv_sec; }
@@ -187,7 +187,7 @@ class utime_t {
187187
t->tv_sec = tv.tv_sec;
188188
t->tv_nsec = tv.tv_nsec;
189189
}
190-
void decode_timeval(const struct ceph_timespec *t) {
190+
constexpr void decode_timeval(const struct ceph_timespec *t) {
191191
tv.tv_sec = t->tv_sec;
192192
tv.tv_nsec = t->tv_nsec;
193193
}
@@ -223,7 +223,7 @@ class utime_t {
223223
}
224224

225225
// cast to double
226-
operator double() const {
226+
constexpr operator double() const {
227227
return (double)sec() + ((double)nsec() / 1000000000.0f);
228228
}
229229
operator ceph_timespec() const {

0 commit comments

Comments
 (0)