Skip to content

Commit

Permalink
Update clag-format to the latest (190926/r372920) version.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 7861ae8ad28eb1f6a06ff3c6f56eff3f67b1d24c
  • Loading branch information
levlam committed Sep 28, 2019
1 parent c7811a0 commit 0b6c1d2
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 163 deletions.
12 changes: 10 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None # All
AllowShortIfStatementsOnASingleLine: false # true
AllowShortIfStatementsOnASingleLine: Never # WithoutElse
AllowShortLambdasOnASingleLine: Inline # All
AllowShortLoopsOnASingleLine: false # true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
Expand All @@ -21,6 +25,7 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
Expand Down Expand Up @@ -60,6 +65,7 @@ ForEachMacros:
- Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
Expand Down Expand Up @@ -87,13 +93,15 @@ ReflowComments: false # true
SortIncludes: false # disabled, because we need case insensitive sort
SortUsingDeclarations: false # true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
Expand Down
48 changes: 21 additions & 27 deletions benchmark/bench_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,13 @@ class CreateFileBench : public Benchmark {
}
}
void tear_down() override {
td::walk_path("A/",
[&](CSlice path, auto type) {
if (type == td::WalkPath::Type::ExitDir) {
rmdir(path).ignore();
} else if (type == td::WalkPath::Type::NotDir) {
unlink(path).ignore();
}
})
.ignore();
td::walk_path("A/", [&](CSlice path, auto type) {
if (type == td::WalkPath::Type::ExitDir) {
rmdir(path).ignore();
} else if (type == td::WalkPath::Type::NotDir) {
unlink(path).ignore();
}
}).ignore();
}
};

Expand All @@ -246,26 +244,22 @@ class WalkPathBench : public Benchmark {
}
void run(int n) override {
int cnt = 0;
td::walk_path("A/",
[&](CSlice path, auto type) {
if (type == td::WalkPath::Type::EnterDir) {
return;
}
stat(path).ok();
cnt++;
})
.ignore();
td::walk_path("A/", [&](CSlice path, auto type) {
if (type == td::WalkPath::Type::EnterDir) {
return;
}
stat(path).ok();
cnt++;
}).ignore();
}
void tear_down() override {
td::walk_path("A/",
[&](CSlice path, auto type) {
if (type == td::WalkPath::Type::ExitDir) {
rmdir(path).ignore();
} else if (type == td::WalkPath::Type::NotDir) {
unlink(path).ignore();
}
})
.ignore();
td::walk_path("A/", [&](CSlice path, auto type) {
if (type == td::WalkPath::Type::ExitDir) {
rmdir(path).ignore();
} else if (type == td::WalkPath::Type::NotDir) {
unlink(path).ignore();
}
}).ignore();
}
};

Expand Down
4 changes: 3 additions & 1 deletion benchmark/check_tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ td::Result<TlsInfo> test_tls(const td::string &url) {

td::string request;

auto add_string = [&](td::Slice data) { request.append(data.data(), data.size()); };
auto add_string = [&](td::Slice data) {
request.append(data.data(), data.size());
};
auto add_random = [&](size_t length) {
while (length-- > 0) {
request += static_cast<char>(td::Random::secure_int32());
Expand Down
4 changes: 2 additions & 2 deletions memprof/memprof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ extern void *__libc_stack_end;
static void *get_bp() {
void *bp;
#if defined(__i386__)
__asm__ volatile("movl %%ebp, %[r]" : [r] "=r"(bp));
__asm__ volatile("movl %%ebp, %[r]" : [ r ] "=r"(bp));
#elif defined(__x86_64__)
__asm__ volatile("movq %%rbp, %[r]" : [r] "=r"(bp));
__asm__ volatile("movq %%rbp, %[r]" : [ r ] "=r"(bp));
#endif
return bp;
}
Expand Down
4 changes: 3 additions & 1 deletion td/mtproto/SessionConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ class SessionConnection
auto set_buffer_slice(BufferSlice *buffer_slice) TD_WARN_UNUSED_RESULT {
auto old_buffer_slice = current_buffer_slice_;
current_buffer_slice_ = buffer_slice;
return ScopeExit() + [&to = current_buffer_slice_, from = old_buffer_slice] { to = from; };
return ScopeExit() + [&to = current_buffer_slice_, from = old_buffer_slice] {
to = from;
};
}

Status parse_message(TlParser &parser, MsgInfo *info, Slice *packet, bool crypto_flag = true) TD_WARN_UNUSED_RESULT;
Expand Down
4 changes: 3 additions & 1 deletion td/telegram/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,9 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
shared_config.set_option_string("photo_search_bot_username", config->img_search_username_);
}

auto fix_timeout_ms = [](int32 timeout_ms) { return clamp(timeout_ms, 1000, 86400 * 1000); };
auto fix_timeout_ms = [](int32 timeout_ms) {
return clamp(timeout_ms, 1000, 86400 * 1000);
};

shared_config.set_option_integer("online_update_period_ms", fix_timeout_ms(config->online_update_period_ms_));

Expand Down
8 changes: 6 additions & 2 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27065,13 +27065,17 @@ void MessagesManager::suffix_load_add_query(Dialog *d,

void MessagesManager::suffix_load_till_date(Dialog *d, int32 date, Promise<> promise) {
LOG(INFO) << "Load suffix of " << d->dialog_id << " till date " << date;
auto condition = [date](const Message *m) { return m != nullptr && m->date < date; };
auto condition = [date](const Message *m) {
return m != nullptr && m->date < date;
};
suffix_load_add_query(d, std::make_pair(std::move(promise), std::move(condition)));
}

void MessagesManager::suffix_load_till_message_id(Dialog *d, MessageId message_id, Promise<> promise) {
LOG(INFO) << "Load suffix of " << d->dialog_id << " till " << message_id;
auto condition = [message_id](const Message *m) { return m != nullptr && m->message_id.get() < message_id.get(); };
auto condition = [message_id](const Message *m) {
return m != nullptr && m->message_id.get() < message_id.get();
};
suffix_load_add_query(d, std::make_pair(std::move(promise), std::move(condition)));
}

Expand Down
4 changes: 3 additions & 1 deletion td/telegram/SecretChatActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,9 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
[&](telegram_api::encryptedFileEmpty &) {
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(
telegram_api::inputEncryptedFileEmpty());
get_file = [] { return telegram_api::make_object<telegram_api::encryptedFileEmpty>(); };
get_file = [] {
return telegram_api::make_object<telegram_api::encryptedFileEmpty>();
};
},
[&](telegram_api::encryptedFile &file) {
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(
Expand Down
4 changes: 3 additions & 1 deletion td/telegram/UpdatesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,9 @@ int32 UpdatesManager::get_short_update_date() const {

tl_object_ptr<td_api::ChatAction> UpdatesManager::convert_send_message_action(
tl_object_ptr<telegram_api::SendMessageAction> action) {
auto fix_progress = [](int32 progress) { return progress <= 0 || progress > 100 ? 0 : progress; };
auto fix_progress = [](int32 progress) {
return progress <= 0 || progress > 100 ? 0 : progress;
};

switch (action->get_id()) {
case telegram_api::sendMessageCancelAction::ID:
Expand Down
56 changes: 27 additions & 29 deletions td/telegram/files/FileStatsWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,33 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
continue;
}
auto files_dir = get_files_dir(file_type);
walk_path(files_dir,
[&](CSlice path, WalkPath::Type type) {
if (token) {
return WalkPath::Action::Abort;
}
if (type != WalkPath::Type::NotDir) {
return WalkPath::Action::Continue;
}
auto r_stat = stat(path);
if (r_stat.is_error()) {
LOG(WARNING) << "Stat in files gc failed: " << r_stat.error();
return WalkPath::Action::Continue;
}
auto stat = r_stat.move_as_ok();
if (ends_with(path, "/.nomedia") && stat.size_ == 0) {
// skip .nomedia file
return WalkPath::Action::Continue;
}

FsFileInfo info;
info.path = path.str();
info.size = stat.size_;
info.file_type = file_type;
info.atime_nsec = stat.atime_nsec_;
info.mtime_nsec = stat.mtime_nsec_;
callback(info);
return WalkPath::Action::Continue;
})
.ignore();
walk_path(files_dir, [&](CSlice path, WalkPath::Type type) {
if (token) {
return WalkPath::Action::Abort;
}
if (type != WalkPath::Type::NotDir) {
return WalkPath::Action::Continue;
}
auto r_stat = stat(path);
if (r_stat.is_error()) {
LOG(WARNING) << "Stat in files gc failed: " << r_stat.error();
return WalkPath::Action::Continue;
}
auto stat = r_stat.move_as_ok();
if (ends_with(path, "/.nomedia") && stat.size_ == 0) {
// skip .nomedia file
return WalkPath::Action::Continue;
}

FsFileInfo info;
info.path = path.str();
info.size = stat.size_;
info.file_type = file_type;
info.atime_nsec = stat.atime_nsec_;
info.mtime_nsec = stat.mtime_nsec_;
callback(info);
return WalkPath::Action::Continue;
}).ignore();
}
}
} // namespace
Expand Down
4 changes: 3 additions & 1 deletion td/telegram/files/PartsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ bool PartsManager::is_part_in_streaming_limit(int part_i) const {
return true;
}

auto is_intersect_with = [&](int64 begin, int64 end) { return max(begin, offset_begin) < min(end, offset_end); };
auto is_intersect_with = [&](int64 begin, int64 end) {
return max(begin, offset_begin) < min(end, offset_end);
};

auto streaming_begin = streaming_offset_;
auto streaming_end = streaming_offset_ + streaming_limit_;
Expand Down
8 changes: 3 additions & 5 deletions td/telegram/net/DcOptionsSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ Result<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_connection(DcId dc_id, b
<< tag("prefer_ipv6", prefer_ipv6));
}

auto last_error_at = std::min_element(options.begin(), options.end(),
[](const auto &a_option, const auto &b_option) {
return a_option.stat->error_at > b_option.stat->error_at;
})
->stat->error_at;
auto last_error_at = std::min_element(options.begin(), options.end(), [](const auto &a_option, const auto &b_option) {
return a_option.stat->error_at > b_option.stat->error_at;
})->stat->error_at;

auto result = *std::min_element(options.begin(), options.end(), [](const auto &a_option, const auto &b_option) {
auto &a = *a_option.stat;
Expand Down
47 changes: 25 additions & 22 deletions tdactor/td/actor/impl/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,37 +229,40 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c

template <ActorSendType send_type, class EventT>
void Scheduler::send_lambda(ActorRef actor_ref, EventT &&lambda) {
return send_impl<send_type>(actor_ref.get(),
[&](ActorInfo *actor_info) {
event_context_ptr_->link_token = actor_ref.token();
lambda();
},
[&]() {
auto event = Event::lambda(std::forward<EventT>(lambda));
event.set_link_token(actor_ref.token());
return event;
});
return send_impl<send_type>(
actor_ref.get(),
[&](ActorInfo *actor_info) {
event_context_ptr_->link_token = actor_ref.token();
lambda();
},
[&]() {
auto event = Event::lambda(std::forward<EventT>(lambda));
event.set_link_token(actor_ref.token());
return event;
});
}

template <ActorSendType send_type, class EventT>
void Scheduler::send_closure(ActorRef actor_ref, EventT &&closure) {
return send_impl<send_type>(actor_ref.get(),
[&](ActorInfo *actor_info) {
event_context_ptr_->link_token = actor_ref.token();
closure.run(static_cast<typename EventT::ActorType *>(actor_info->get_actor_unsafe()));
},
[&]() {
auto event = Event::immediate_closure(std::forward<EventT>(closure));
event.set_link_token(actor_ref.token());
return event;
});
return send_impl<send_type>(
actor_ref.get(),
[&](ActorInfo *actor_info) {
event_context_ptr_->link_token = actor_ref.token();
closure.run(static_cast<typename EventT::ActorType *>(actor_info->get_actor_unsafe()));
},
[&]() {
auto event = Event::immediate_closure(std::forward<EventT>(closure));
event.set_link_token(actor_ref.token());
return event;
});
}

template <ActorSendType send_type>
void Scheduler::send(ActorRef actor_ref, Event &&event) {
event.set_link_token(actor_ref.token());
return send_impl<send_type>(actor_ref.get(), [&](ActorInfo *actor_info) { do_event(actor_info, std::move(event)); },
[&]() { return std::move(event); });
return send_impl<send_type>(
actor_ref.get(), [&](ActorInfo *actor_info) { do_event(actor_info, std::move(event)); },
[&]() { return std::move(event); });
}

inline void Scheduler::subscribe(PollableFd fd, PollFlags flags) {
Expand Down
15 changes: 8 additions & 7 deletions tddb/td/db/BinlogKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ class BinlogKeyValue : public KeyValueSyncInterface {
}

binlog_ = std::make_shared<BinlogT>();
TRY_STATUS(binlog_->init(name,
[&](const BinlogEvent &binlog_event) {
Event event;
event.parse(TlParser(binlog_event.data_));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
},
std::move(db_key), DbKey::empty(), scheduler_id));
TRY_STATUS(binlog_->init(
name,
[&](const BinlogEvent &binlog_event) {
Event event;
event.parse(TlParser(binlog_event.data_));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
},
std::move(db_key), DbKey::empty(), scheduler_id));
return Status::OK();
}

Expand Down
4 changes: 3 additions & 1 deletion tddb/td/db/SqliteKeyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Result<bool> SqliteKeyValue::init(string path) {
}

Status SqliteKeyValue::init_with_connection(SqliteDb connection, string table_name) {
auto init_guard = ScopeExit() + [&]() { close(); };
auto init_guard = ScopeExit() + [&]() {
close();
};
db_ = std::move(connection);
table_name_ = std::move(table_name);
TRY_STATUS(init(db_, table_name_));
Expand Down
Loading

0 comments on commit 0b6c1d2

Please sign in to comment.