diff options
| author | levlam <levlam@telegram.org> | 2021-11-01 01:24:51 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2021-11-01 01:24:51 +0300 |
| commit | c66cf3dec6c23016ef44fed9a888053f2f5fc9ce (patch) | |
| tree | f0692da5d737a00e9dac374a2beab7cb7eb2efb7 | |
| parent | 7cd7e5afd38cb32439ecad62bb81c5bb8eb26a8a (diff) | |
Use range-based for on arrays/strings if possible.
| -rw-r--r-- | benchmark/bench_crypto.cpp | 49 | ||||
| -rw-r--r-- | benchmark/check_tls.cpp | 4 | ||||
| -rw-r--r-- | td/telegram/MessageEntity.cpp | 4 | ||||
| -rw-r--r-- | td/telegram/StickersManager.cpp | 1 | ||||
| -rw-r--r-- | tdtl/td/tl/tl_simple.h | 6 |
5 files changed, 21 insertions, 43 deletions
diff --git a/benchmark/bench_crypto.cpp b/benchmark/bench_crypto.cpp index b6d36c237..f915fbcf9 100644 --- a/benchmark/bench_crypto.cpp +++ b/benchmark/bench_crypto.cpp @@ -17,10 +17,12 @@ #include <openssl/evp.h> #include <openssl/sha.h> +#include <algorithm> #include <array> #include <atomic> #include <cstdint> #include <cstdlib> +#include <iterator> #include <random> #include <string> #include <vector> @@ -38,10 +40,7 @@ class SHA1Bench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - data[i] = 0; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); } void run(int n) final { @@ -64,9 +63,7 @@ class AesEcbBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(key.raw, sizeof(key)); td::Random::secure_bytes(iv.raw, sizeof(iv)); } @@ -95,9 +92,7 @@ class AesIgeEncryptBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(key.raw, sizeof(key)); td::Random::secure_bytes(iv.raw, sizeof(iv)); } @@ -123,9 +118,7 @@ class AesIgeDecryptBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(key.raw, sizeof(key)); td::Random::secure_bytes(iv.raw, sizeof(iv)); } @@ -151,9 +144,7 @@ class AesCtrBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(key.raw, sizeof(key)); td::Random::secure_bytes(iv.raw, sizeof(iv)); } @@ -180,9 +171,7 @@ class AesCtrOpenSSLBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(key.raw, sizeof(key)); td::Random::secure_bytes(iv.raw, sizeof(iv)); } @@ -216,9 +205,7 @@ class AesCbcDecryptBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(as_slice(key)); td::Random::secure_bytes(as_slice(iv)); } @@ -242,9 +229,7 @@ class AesCbcEncryptBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(as_slice(key)); td::Random::secure_bytes(as_slice(iv)); } @@ -269,9 +254,7 @@ class AesIgeShortBench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < SHORT_DATA_SIZE; i++) { - data[i] = 123; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); td::Random::secure_bytes(as_slice(key)); td::Random::secure_bytes(as_slice(iv)); } @@ -372,10 +355,7 @@ class Crc32Bench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - data[i] = 0; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); } void run(int n) final { @@ -396,10 +376,7 @@ class Crc64Bench final : public td::Benchmark { } void start_up() final { - for (int i = 0; i < DATA_SIZE; i++) { - data[i] = 123; - data[i] = 0; - } + std::fill(std::begin(data), std::end(data), static_cast<unsigned char>(123)); } void run(int n) final { diff --git a/benchmark/check_tls.cpp b/benchmark/check_tls.cpp index afc80b800..b2fa2ecd0 100644 --- a/benchmark/check_tls.cpp +++ b/benchmark/check_tls.cpp @@ -96,8 +96,8 @@ td::Result<TlsInfo> test_tls(const td::string &url) { const size_t MAX_GREASE = 7; char greases[MAX_GREASE]; td::Random::secure_bytes(td::MutableSlice{greases, MAX_GREASE}); - for (size_t i = 0; i < MAX_GREASE; i++) { - greases[i] = static_cast<char>((greases[i] & 0xF0) + 0x0A); + for (auto &grease : greases) { + grease = static_cast<char>((grease & 0xF0) + 0x0A); } for (size_t i = 1; i < MAX_GREASE; i += 2) { if (greases[i] == greases[i - 1]) { diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 0a4203f0c..c091b7ec7 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -2223,8 +2223,8 @@ static FormattedText parse_text_url_entities_v3(Slice text, const vector<Message } size_t splittable_entity_pos[SPLITTABLE_ENTITY_TYPE_COUNT] = {}; - for (size_t index = 0; index < SPLITTABLE_ENTITY_TYPE_COUNT; index++) { - check_non_intersecting(part_splittable_entities[index]); + for (const auto &splittable_entities : part_splittable_entities) { + check_non_intersecting(splittable_entities); } if (part_end != max_end) { // try to find text_url entities in the left part diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 79921e5bc..56a4758b5 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6204,6 +6204,7 @@ void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limi for (int is_attached = 0; is_attached < 2; is_attached++) { if (static_cast<int32>(recent_sticker_ids_[is_attached].size()) > recent_stickers_limit) { recent_sticker_ids_[is_attached].resize(recent_stickers_limit); + need_update_recent_stickers_[is_attached] = true; send_update_recent_stickers(); } } diff --git a/tdtl/td/tl/tl_simple.h b/tdtl/td/tl/tl_simple.h index 67ad2a1aa..7647981bf 100644 --- a/tdtl/td/tl/tl_simple.h +++ b/tdtl/td/tl/tl_simple.h @@ -23,9 +23,9 @@ namespace tl { namespace simple { inline std::string gen_cpp_name(std::string name) { - for (std::size_t i = 0; i < name.size(); i++) { - if ((name[i] < '0' || '9' < name[i]) && (name[i] < 'a' || 'z' < name[i]) && (name[i] < 'A' || 'Z' < name[i])) { - name[i] = '_'; + for (auto &c : name) { + if ((c < '0' || '9' < c) && (c < 'a' || 'z' < c) && (c < 'A' || 'Z' < c)) { + c = '_'; } } assert(!name.empty()); |
