Skip to content

Commit 3c5df2c

Browse files
authored
Remove less and use std (#658)
* Remove less and use std Signed-off-by: ortyomka <[email protected]>
1 parent 7942df5 commit 3c5df2c

File tree

10 files changed

+27
-39
lines changed

10 files changed

+27
-39
lines changed

core/codec/cbor/cbor_dump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace fc {
2929

3030
struct LessCborKey {
3131
bool operator()(const std::string &l, const std::string &r) const {
32-
return less(
33-
l.size(), r.size(), common::span::cbytes(l), common::span::cbytes(r));
32+
return std::forward_as_tuple(l.size(), common::span::cbytes(l))
33+
< std::forward_as_tuple(r.size(), common::span::cbytes(r));
3434
}
3535
};
3636

core/codec/cbor/cbor_encode_stream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ namespace fc::codec::cbor {
8181

8282
struct LessCborKey {
8383
bool operator()(BytesIn lhs, BytesIn rhs) const {
84-
return less(lhs.size(), rhs.size(), lhs, rhs);
84+
return std::forward_as_tuple(lhs.size(), lhs)
85+
< std::forward_as_tuple(rhs.size(), rhs);
8586
}
8687
};
8788

core/common/cmp.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@
1010
return !(l == r); \
1111
}
1212
#define FC_OPERATOR_NOT_EQUAL(T) FC_OPERATOR_NOT_EQUAL_2(T, T)
13-
14-
namespace fc {
15-
inline auto less() {
16-
return false;
17-
}
18-
19-
template <typename T, typename... Ts>
20-
inline auto less(const T &l, const T &r, const Ts &...ts) {
21-
return l < r || (!(r < l) && less(ts...));
22-
}
23-
} // namespace fc

core/paych/vouchers.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ namespace fc::paych_vouchers {
7676
if (lane_it == row.lanes.end() || lane_it->lane != voucher.lane) {
7777
lane_it = row.lanes.emplace(lane_it, LaneVouchers{voucher.lane});
7878
}
79-
const auto voucher_it{
80-
std::lower_bound(lane_it->vouchers.begin(),
81-
lane_it->vouchers.end(),
82-
voucher,
83-
[](const SignedVoucher &l, const SignedVoucher &r) {
84-
return less(l.lane, r.lane, l.nonce, r.nonce);
85-
})};
79+
const auto voucher_it{std::lower_bound(
80+
lane_it->vouchers.begin(),
81+
lane_it->vouchers.end(),
82+
voucher,
83+
[](const SignedVoucher &l, const SignedVoucher &r) {
84+
return std::tie(l.lane, l.nonce) < std::tie(r.lane, r.nonce);
85+
})};
8686
const auto found{voucher_it != lane_it->vouchers.end()
8787
&& voucher_it->lane == voucher.lane
8888
&& voucher_it->nonce == voucher.nonce};

core/primitives/address/address.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "primitives/address/address.hpp"
77

8-
#include "common/cmp.hpp"
98
#include "common/visitor.hpp"
109
#include "crypto/blake2/blake2b160.hpp"
1110

@@ -117,7 +116,8 @@ namespace fc::primitives::address {
117116
}
118117

119118
bool operator<(const Address &lhs, const Address &rhs) {
120-
return less(lhs.getProtocol(), rhs.getProtocol(), lhs.data, rhs.data);
119+
return std::forward_as_tuple(lhs.getProtocol(), lhs.data)
120+
< std::forward_as_tuple(rhs.getProtocol(), rhs.data);
121121
}
122122

123123
} // namespace fc::primitives::address

core/primitives/sector/sector.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#pragma once
77

88
#include "common/blob.hpp"
9-
#include "common/cmp.hpp"
109
#include "common/enum.hpp"
1110
#include "crypto/randomness/randomness_types.hpp"
1211
#include "primitives/cid/cid.hpp"
@@ -26,7 +25,7 @@ namespace fc::primitives::sector {
2625
SectorNumber sector;
2726
};
2827
inline bool operator<(const SectorId &lhs, const SectorId &rhs) {
29-
return less(lhs.miner, rhs.miner, lhs.sector, rhs.sector);
28+
return std::tie(lhs.miner, lhs.sector) < std::tie(rhs.miner, rhs.sector);
3029
}
3130
inline bool operator==(const SectorId &lhs, const SectorId &rhs) {
3231
return lhs.miner == rhs.miner && lhs.sector == rhs.sector;

core/sector_storage/impl/scheduler_impl.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ namespace fc::sector_storage {
5656
};
5757

5858
inline bool operator<(const TaskRequest &lhs, const TaskRequest &rhs) {
59-
return less(rhs.priority,
60-
lhs.priority,
61-
lhs.task_type,
62-
rhs.task_type,
63-
lhs.sector.id.sector,
64-
rhs.sector.id.sector);
59+
// priority is intentionally reversed
60+
return std::tie(rhs.priority, lhs.task_type, lhs.sector.id.sector)
61+
< std::tie(lhs.priority, rhs.task_type, rhs.sector.id.sector);
6562
}
6663

6764
class SchedulerImpl : public Scheduler {

core/sector_storage/stores/impl/index_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace fc::sector_storage::stores {
2828
};
2929

3030
inline bool operator<(const Decl &lhs, const Decl &rhs) {
31-
return less(lhs.sector_id, rhs.sector_id, lhs.type, rhs.type);
31+
return std::tie(lhs.sector_id, lhs.type)
32+
< std::tie(rhs.sector_id, rhs.type);
3233
}
3334

3435
class SectorIndexImpl : public SectorIndex {

core/sector_storage/worker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace fc::sector_storage {
5656
CBOR_TUPLE(CallId, sector, id);
5757

5858
inline bool operator<(const CallId &lhs, const CallId &rhs) {
59-
return less(lhs.sector, rhs.sector, lhs.id, rhs.id);
59+
return std::tie(lhs.sector, lhs.id) < std::tie(rhs.sector, rhs.id);
6060
}
6161

6262
inline bool operator==(const CallId &lhs, const CallId &rhs) {

core/storage/mpool/mpool.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ namespace fc::storage::mpool {
134134
}
135135

136136
bool before(const MsgChain &l, const MsgChain &r) {
137-
return less(r.gas_perf, l.gas_perf, r.gas_reward, l.gas_reward);
137+
// right and left are intentionally reversed
138+
return std::tie(r.gas_perf, r.gas_reward)
139+
< std::tie(l.gas_perf, l.gas_reward);
138140
}
139141

140142
bool beforeEffective(const MsgChain &l, const MsgChain &r) {
141143
return (l.merged && !r.merged) || (l.gas_perf >= 0 && r.gas_perf < 0)
142-
|| less(r.eff_perf,
144+
|| (std::tie(r.eff_perf, r.gas_perf, r.gas_reward) < std::tie(
143145
l.eff_perf,
144-
r.gas_perf,
145146
l.gas_perf,
146-
r.gas_reward,
147-
l.gas_reward);
147+
l.gas_reward)); // right and left are intentionally reversed
148148
}
149149

150150
template <typename F>
@@ -729,7 +729,8 @@ namespace fc::storage::mpool {
729729
}
730730

731731
std::sort(prices.begin(), prices.end(), [](auto &l, auto &r) {
732-
return less(r.first, l.first, l.second, r.second);
732+
// second is intentionally reversed
733+
return std::tie(r.first, l.second) < std::tie(l.first, r.second);
733734
});
734735
auto at = static_cast<int64_t>(kBlockGasTarget * blocks / 2);
735736
TokenAmount premium;

0 commit comments

Comments
 (0)