Use range-based for on arrays/strings if possible.
This commit is contained in:
parent
7cd7e5afd3
commit
c66cf3dec6
@ -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 {
|
||||
|
@ -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]) {
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user