Skip to content

Commit 2d2fdd9

Browse files
authored
refactor(RimeWithWeasel): Reduce redundant _GetCandidateInfo() calls by computing candidates once per context. (#1750)
1 parent ef9c8b3 commit 2d2fdd9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

RimeWithWeasel/RimeWithWeasel.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,11 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) {
789789

790790
RIME_STRUCT(RimeContext, ctx);
791791
if (rime_api->get_context(session_id, &ctx)) {
792+
bool has_candidates = ctx.menu.num_candidates > 0;
793+
CandidateInfo cinfo;
794+
if (has_candidates) {
795+
_GetCandidateInfo(cinfo, ctx);
796+
}
792797
if (is_composing) {
793798
actions.insert("ctx");
794799
switch (session_status.style.preedit_type) {
@@ -826,8 +831,6 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) {
826831
}
827832
break;
828833
case UIStyle::PREVIEW_ALL:
829-
CandidateInfo cinfo;
830-
_GetCandidateInfo(cinfo, ctx);
831834
std::string topush = std::string("ctx.preedit=") +
832835
escape_string<char>(ctx.composition.preedit) +
833836
" [";
@@ -867,11 +870,9 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) {
867870
break;
868871
}
869872
}
870-
if (ctx.menu.num_candidates) {
871-
CandidateInfo cinfo;
873+
if (has_candidates) {
872874
std::wstringstream ss;
873875
boost::archive::text_woarchive oa(ss);
874-
_GetCandidateInfo(cinfo, ctx);
875876

876877
oa << cinfo;
877878

0 commit comments

Comments
 (0)