aboutsummaryrefslogtreecommitdiffhomepage
path: root/benchmark
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2021-08-22 22:08:46 +0300
committerlevlam <levlam@telegram.org>2021-08-22 22:08:46 +0300
commit6507fb7602e4c25210788abbaa4e18e5d2abc506 (patch)
treecd3042949a5307630ca81e0143b3218e16893b8d /benchmark
parentb3aa31d39800c5f88e23c3975b64723814c7d523 (diff)
Use array-based MessageIdDuplicateChecker.
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/bench_misc.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/benchmark/bench_misc.cpp b/benchmark/bench_misc.cpp
index e3671a3e7..aeec2232a 100644
--- a/benchmark/bench_misc.cpp
+++ b/benchmark/bench_misc.cpp
@@ -533,40 +533,40 @@ class MessageIdDuplicateCheckerNewSimple {
std::set<td::int64> saved_message_ids_;
};
-template <size_t MAX_SAVED_MESSAGE_IDS>
+template <size_t max_size>
class MessageIdDuplicateCheckerArray {
public:
static td::string get_description() {
- return PSTRING() << "Array" << MAX_SAVED_MESSAGE_IDS;
+ return PSTRING() << "Array" << max_size;
}
td::Status check(td::int64 message_id) {
- if (end_pos == 2 * MAX_SAVED_MESSAGE_IDS) {
- std::copy_n(&saved_message_ids_[MAX_SAVED_MESSAGE_IDS], MAX_SAVED_MESSAGE_IDS, &saved_message_ids_[0]);
- end_pos = MAX_SAVED_MESSAGE_IDS;
+ if (end_pos_ == 2 * max_size) {
+ std::copy_n(&saved_message_ids_[max_size], max_size, &saved_message_ids_[0]);
+ end_pos_ = max_size;
}
- if (end_pos == 0 || message_id > saved_message_ids_[end_pos - 1]) {
+ if (end_pos_ == 0 || message_id > saved_message_ids_[end_pos_ - 1]) {
// fast path
- saved_message_ids_[end_pos++] = message_id;
+ saved_message_ids_[end_pos_++] = message_id;
return td::Status::OK();
}
- if (end_pos >= MAX_SAVED_MESSAGE_IDS && message_id < saved_message_ids_[0]) {
+ if (end_pos_ >= max_size && message_id < saved_message_ids_[0]) {
return td::Status::Error(2, PSLICE() << "Ignore very old message_id "
<< td::tag("oldest message_id", saved_message_ids_[0])
<< td::tag("got message_id", message_id));
}
- auto it = std::lower_bound(&saved_message_ids_[0], &saved_message_ids_[end_pos], message_id);
+ auto it = std::lower_bound(&saved_message_ids_[0], &saved_message_ids_[end_pos_], message_id);
if (*it == message_id) {
return td::Status::Error(1, PSLICE() << "Ignore duplicated message_id " << td::tag("message_id", message_id));
}
- std::copy_backward(it, &saved_message_ids_[end_pos], &saved_message_ids_[end_pos + 1]);
+ std::copy_backward(it, &saved_message_ids_[end_pos_], &saved_message_ids_[end_pos_ + 1]);
*it = message_id;
- ++end_pos;
+ ++end_pos_;
return td::Status::OK();
}
private:
- std::array<td::int64, 2 * MAX_SAVED_MESSAGE_IDS> saved_message_ids_;
- std::size_t end_pos = 0;
+ std::array<td::int64, 2 * max_size> saved_message_ids_;
+ std::size_t end_pos_ = 0;
};
template <class T>