Improve constant name.

GitOrigin-RevId: 650c2c1ef42bb4d31f4cd5094cca5d251cc6c28a
This commit is contained in:
levlam 2020-06-22 02:27:58 +03:00
parent d75c6eff57
commit 32af19acfe
8 changed files with 16 additions and 16 deletions

View File

@ -35,7 +35,7 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
// may write something more clever, but i will need at least 2 passes over the files // may write something more clever, but i will need at least 2 passes over the files
// TODO update atime for all files in android (?) // TODO update atime for all files in android (?)
std::array<bool, file_type_size> immune_types{{false}}; std::array<bool, MAX_FILE_TYPE> immune_types{{false}};
if (G()->parameters().use_file_db) { if (G()->parameters().use_file_db) {
// immune by default // immune by default

View File

@ -764,7 +764,7 @@ FileManager::FileManager(unique_ptr<Context> context) : context_(std::move(conte
FileFd::open(dirs.back() + ".nomedia", FileFd::Create | FileFd::Read).ignore(); FileFd::open(dirs.back() + ".nomedia", FileFd::Create | FileFd::Read).ignore();
#endif #endif
}; };
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
FileType file_type = static_cast<FileType>(i); FileType file_type = static_cast<FileType>(i);
if (file_type == FileType::SecureRaw || file_type == FileType::Background || if (file_type == FileType::SecureRaw || file_type == FileType::Background ||
file_type == FileType::DocumentAsFile) { file_type == FileType::DocumentAsFile) {

View File

@ -55,7 +55,7 @@ void FileStats::add(FullFileInfo &&info) {
FileTypeStat get_nontemp_stat(const FileStats::StatByType &by_type) { FileTypeStat get_nontemp_stat(const FileStats::StatByType &by_type) {
FileTypeStat stat; FileTypeStat stat;
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
if (FileType(i) != FileType::Temp) { if (FileType(i) != FileType::Temp) {
stat.size += by_type[i].size; stat.size += by_type[i].size;
stat.cnt += by_type[i].cnt; stat.cnt += by_type[i].cnt;
@ -116,7 +116,7 @@ void FileStats::apply_dialog_limit(int32 limit) {
if (all_dialogs.count(it->first)) { if (all_dialogs.count(it->first)) {
++it; ++it;
} else { } else {
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
other_stats[i].size += it->second[i].size; other_stats[i].size += it->second[i].size;
other_stats[i].cnt += it->second[i].cnt; other_stats[i].cnt += it->second[i].cnt;
} }
@ -140,7 +140,7 @@ tl_object_ptr<td_api::storageStatisticsByChat> as_td_api(DialogId dialog_id,
int32 wallpaper_raw_cnt = 0; int32 wallpaper_raw_cnt = 0;
int64 document_raw_size = 0; int64 document_raw_size = 0;
int32 document_raw_cnt = 0; int32 document_raw_cnt = 0;
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
FileType file_type = static_cast<FileType>(i); FileType file_type = static_cast<FileType>(i);
auto size = stat_by_type[i].size; auto size = stat_by_type[i].size;
auto cnt = stat_by_type[i].cnt; auto cnt = stat_by_type[i].cnt;
@ -236,7 +236,7 @@ StringBuilder &operator<<(StringBuilder &sb, const FileStats &file_stats) {
} }
sb << "[FileStat " << tag("total", total_stat); sb << "[FileStat " << tag("total", total_stat);
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
sb << tag(get_file_type_name(FileType(i)), file_stats.stat_by_type[i]); sb << tag(get_file_type_name(FileType(i)), file_stats.stat_by_type[i]);
} }
sb << "]"; sb << "]";
@ -259,7 +259,7 @@ StringBuilder &operator<<(StringBuilder &sb, const FileStats &file_stats) {
} }
sb << "[FileStat " << tag("owner_dialog_id", by_type.first) << tag("total", dialog_stat); sb << "[FileStat " << tag("owner_dialog_id", by_type.first) << tag("total", dialog_stat);
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
sb << tag(get_file_type_name(FileType(i)), by_type.second[i]); sb << tag(get_file_type_name(FileType(i)), by_type.second[i]);
} }
sb << "]"; sb << "]";

View File

@ -72,7 +72,7 @@ struct FileStats {
bool need_all_files{false}; bool need_all_files{false};
bool split_by_owner_dialog_id{false}; bool split_by_owner_dialog_id{false};
using StatByType = std::array<FileTypeStat, file_type_size>; using StatByType = std::array<FileTypeStat, MAX_FILE_TYPE>;
StatByType stat_by_type; StatByType stat_by_type;
std::unordered_map<DialogId, StatByType, DialogIdHash> stat_by_owner_dialog_id; std::unordered_map<DialogId, StatByType, DialogIdHash> stat_by_owner_dialog_id;

View File

@ -100,7 +100,7 @@ struct FsFileInfo {
template <class CallbackT> template <class CallbackT>
void scan_fs(CancellationToken &token, CallbackT &&callback) { void scan_fs(CancellationToken &token, CallbackT &&callback) {
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
auto file_type = static_cast<FileType>(i); auto file_type = static_cast<FileType>(i);
if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper || file_type == FileType::DocumentAsFile) { if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper || file_type == FileType::DocumentAsFile) {
continue; continue;

View File

@ -39,7 +39,7 @@ enum class FileType : int32 {
enum class FileDirType : int8 { Secure, Common }; enum class FileDirType : int8 { Secure, Common };
constexpr int32 file_type_size = static_cast<int32>(FileType::Size); constexpr int32 MAX_FILE_TYPE = static_cast<int32>(FileType::Size);
FileType from_td_api(const td_api::FileType &file_type); FileType from_td_api(const td_api::FileType &file_type);

View File

@ -126,14 +126,14 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
entry.rx = static_cast<int64>(static_cast<double>(total.read_size) * entry.rx = static_cast<int64>(static_cast<double>(total.read_size) *
(static_cast<double>(entry.rx) / static_cast<double>(total_files.read_size))); (static_cast<double>(entry.rx) / static_cast<double>(total_files.read_size)));
} else { } else {
// entry.rx += total.read_size / file_type_size; // entry.rx += total.read_size / MAX_FILE_TYPE;
} }
if (total_files.write_size != 0) { if (total_files.write_size != 0) {
entry.tx = static_cast<int64>(static_cast<double>(total.write_size) * entry.tx = static_cast<int64>(static_cast<double>(total.write_size) *
(static_cast<double>(entry.tx) / static_cast<double>(total_files.write_size))); (static_cast<double>(entry.tx) / static_cast<double>(total_files.write_size)));
} else { } else {
// entry.tx += total.write_size / file_type_size; // entry.tx += total.write_size / MAX_FILE_TYPE;
} }
check.read_size += entry.rx; check.read_size += entry.rx;
check.write_size += entry.tx; check.write_size += entry.tx;
@ -175,7 +175,7 @@ void NetStatsManager::add_network_stats(const NetworkStatsEntry &entry) {
} }
add_network_stats_impl(media_net_stats_, entry); add_network_stats_impl(media_net_stats_, entry);
size_t file_type_n = static_cast<size_t>(entry.file_type); size_t file_type_n = static_cast<size_t>(entry.file_type);
CHECK(file_type_n < static_cast<size_t>(file_type_size)); CHECK(file_type_n < static_cast<size_t>(MAX_FILE_TYPE));
add_network_stats_impl(files_stats_[file_type_n], entry); add_network_stats_impl(files_stats_[file_type_n], entry);
} }

View File

@ -117,15 +117,15 @@ class NetStatsManager : public Actor {
int32 since_current_{0}; int32 since_current_{0};
NetStatsInfo common_net_stats_; NetStatsInfo common_net_stats_;
NetStatsInfo media_net_stats_; NetStatsInfo media_net_stats_;
std::array<NetStatsInfo, file_type_size> files_stats_; std::array<NetStatsInfo, MAX_FILE_TYPE> files_stats_;
NetStatsInfo call_net_stats_; NetStatsInfo call_net_stats_;
static constexpr int32 CALL_NET_STATS_ID{file_type_size + 2}; static constexpr int32 CALL_NET_STATS_ID{MAX_FILE_TYPE + 2};
template <class F> template <class F>
void for_each_stat(F &&f) { void for_each_stat(F &&f) {
f(common_net_stats_, 0, CSlice("common"), FileType::None); f(common_net_stats_, 0, CSlice("common"), FileType::None);
f(media_net_stats_, 1, CSlice("media"), FileType::None); f(media_net_stats_, 1, CSlice("media"), FileType::None);
for (int32 file_type_i = 0; file_type_i < file_type_size; file_type_i++) { for (int32 file_type_i = 0; file_type_i < MAX_FILE_TYPE; file_type_i++) {
auto &stat = files_stats_[file_type_i]; auto &stat = files_stats_[file_type_i];
auto file_type = static_cast<FileType>(file_type_i); auto file_type = static_cast<FileType>(file_type_i);
f(stat, file_type_i + 2, get_file_type_name(file_type), file_type); f(stat, file_type_i + 2, get_file_type_name(file_type), file_type);