Skip to content

Commit

Permalink
refactor: replace std::bind with lambda to increase readability
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Jun 21, 2024
1 parent 2f89098 commit 9147f74
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/rime/algo/syllabifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Corrector;
using SyllableId = int32_t;

struct EdgeProperties : SpellingProperties {
EdgeProperties(SpellingProperties sup) : SpellingProperties(sup) {};
EdgeProperties(SpellingProperties sup) : SpellingProperties(sup){};
EdgeProperties() = default;
bool is_correction = false;
};
Expand Down
16 changes: 10 additions & 6 deletions src/rime/gear/key_binder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <rime/switches.h>
#include <rime/gear/key_binder.h>

using namespace std::placeholders;

namespace rime {

enum KeyBindingCondition {
Expand Down Expand Up @@ -197,13 +195,19 @@ void KeyBindings::LoadBindings(const an<ConfigList>& bindings) {
continue;
}
} else if (auto option = map->GetValue("toggle")) {
binding.action = std::bind(&toggle_option, _1, option->str());
binding.action = [&](auto engine) {
toggle_option(engine, option->str());
};
} else if (auto option = map->GetValue("set_option")) {
binding.action = std::bind(&set_option, _1, option->str());
binding.action = [&](auto engine) { set_option(engine, option->str()); };
} else if (auto option = map->GetValue("unset_option")) {
binding.action = std::bind(&unset_option, _1, option->str());
binding.action = [&](auto engine) {
unset_option(engine, option->str());
};
} else if (auto schema = map->GetValue("select")) {
binding.action = std::bind(&select_schema, _1, schema->str());
binding.action = [&](auto engine) {
select_schema(engine, option->str());
};
} else {
LOG(WARNING) << "invalid key binding #" << i << ".";
continue;
Expand Down
2 changes: 0 additions & 2 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <windows.h>
#endif

using namespace std::placeholders;

namespace fs = std::filesystem;

namespace rime {
Expand Down
9 changes: 5 additions & 4 deletions src/rime/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ namespace rime {

Session::Session() {
engine_.reset(Engine::Create());
engine_->sink().connect(std::bind(&Session::OnCommit, this, _1));
engine_->sink().connect([&](auto text) { OnCommit(text); });
SessionId session_id = reinterpret_cast<SessionId>(this);
engine_->message_sink().connect(
std::bind(&Service::Notify, &Service::instance(), session_id, _1, _2));
engine_->message_sink().connect([session_id](auto type, auto value) {
Service::instance().Notify(session_id, type, value);
});
}

bool Session::ProcessKey(const KeyEvent& key_event) {
Expand Down Expand Up @@ -65,7 +66,7 @@ Schema* Session::schema() const {

Service::Service() {
deployer_.message_sink().connect(
std::bind(&Service::Notify, this, 0, _1, _2));
[&](auto type, auto value) { Notify(0, type, value); });
}

Service::~Service() {
Expand Down
5 changes: 3 additions & 2 deletions src/rime_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ RIME_DEPRECATED void RimeSetup(RimeTraits* traits) {

RIME_DEPRECATED void RimeSetNotificationHandler(RimeNotificationHandler handler,
void* context_object) {
using namespace std::placeholders;
if (handler) {
Service::instance().SetNotificationHandler(
std::bind(handler, context_object, _1, _2, _3));
[context_object, &handler](auto id, auto type, auto value) {
handler(context_object, id, type, value);
});
} else {
Service::instance().ClearNotificationHandler();
}
Expand Down

0 comments on commit 9147f74

Please sign in to comment.