Skip to content

Commit 582081b

Browse files
committed
refactor: remove redundant run state checking
librime does it inside.
1 parent 7d50a8c commit 582081b

File tree

2 files changed

+3
-69
lines changed

2 files changed

+3
-69
lines changed

app/src/main/java/com/osfans/trime/core/Rime.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Rime :
172172
limit: Int,
173173
): Array<CandidateItem> =
174174
withRimeContext {
175-
getRimeCandidates(startIndex, limit) ?: emptyArray()
175+
getRimeCandidates(startIndex, limit)
176176
}
177177

178178
private fun handleRimeMessage(it: RimeMessage<*>) {
@@ -410,7 +410,7 @@ class Rime :
410410
external fun getRimeCandidates(
411411
startIndex: Int,
412412
limit: Int,
413-
): Array<CandidateItem>?
413+
): Array<CandidateItem>
414414

415415
@JvmStatic
416416
fun handleRimeMessage(

app/src/main/jni/librime_jni/rime_jni.cc

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class Rime {
3333
return instance;
3434
}
3535

36-
bool isRunning() { return session != 0; }
37-
3836
void startup(bool fullCheck,
3937
const RimeNotificationHandler &notificationHandler) {
4038
if (!rime) return;
@@ -153,7 +151,7 @@ class Rime {
153151

154152
bool sync() { return rime->sync_user_data(); }
155153

156-
RimeSessionId sessionId() const { return session; }
154+
[[nodiscard]] RimeSessionId sessionId() const { return session; }
157155

158156
private:
159157
RimeApi *rime;
@@ -162,9 +160,6 @@ class Rime {
162160
bool firstRun = true;
163161
};
164162

165-
// check rime status
166-
static inline bool is_rime_running() { return Rime::Instance().isRunning(); }
167-
168163
GlobalRefSingleton *GlobalRef;
169164

170165
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
@@ -176,10 +171,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
176171
extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_startupRime(
177172
JNIEnv *env, jclass clazz, jstring shared_dir, jstring user_dir,
178173
jboolean full_check) {
179-
if (is_rime_running()) {
180-
return;
181-
}
182-
183174
// for rime shared data dir
184175
setenv("RIME_SHARED_DATA_DIR", CString(env, shared_dir), 1);
185176
// for rime user data dir
@@ -209,9 +200,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_startupRime(
209200

210201
extern "C" JNIEXPORT void JNICALL
211202
Java_com_osfans_trime_core_Rime_exitRime(JNIEnv *env, jclass /* thiz */) {
212-
if (!is_rime_running()) {
213-
return;
214-
}
215203
Rime::Instance().exit();
216204
}
217205

@@ -242,36 +230,24 @@ Java_com_osfans_trime_core_Rime_syncRimeUserData(JNIEnv *env,
242230
extern "C" JNIEXPORT jboolean JNICALL
243231
Java_com_osfans_trime_core_Rime_processRimeKey(JNIEnv *env, jclass /* thiz */,
244232
jint keycode, jint mask) {
245-
if (!is_rime_running()) {
246-
return false;
247-
}
248233
return Rime::Instance().processKey(keycode, mask);
249234
}
250235

251236
extern "C" JNIEXPORT jboolean JNICALL
252237
Java_com_osfans_trime_core_Rime_commitRimeComposition(JNIEnv *env,
253238
jclass /* thiz */) {
254-
if (!is_rime_running()) {
255-
return false;
256-
}
257239
return Rime::Instance().commitComposition();
258240
}
259241

260242
extern "C" JNIEXPORT void JNICALL
261243
Java_com_osfans_trime_core_Rime_clearRimeComposition(JNIEnv *env,
262244
jclass /* thiz */) {
263-
if (!is_rime_running()) {
264-
return;
265-
}
266245
Rime::Instance().clearComposition();
267246
}
268247

269248
// output
270249
extern "C" JNIEXPORT jobject JNICALL
271250
Java_com_osfans_trime_core_Rime_getRimeCommit(JNIEnv *env, jclass /* thiz */) {
272-
if (!is_rime_running()) {
273-
return nullptr;
274-
}
275251
RIME_STRUCT(RimeCommit, commit)
276252
auto rime = rime_get_api();
277253
jobject obj = nullptr;
@@ -284,9 +260,6 @@ Java_com_osfans_trime_core_Rime_getRimeCommit(JNIEnv *env, jclass /* thiz */) {
284260

285261
extern "C" JNIEXPORT jobject JNICALL
286262
Java_com_osfans_trime_core_Rime_getRimeContext(JNIEnv *env, jclass /* thiz */) {
287-
if (!is_rime_running()) {
288-
return nullptr;
289-
}
290263
RIME_STRUCT(RimeContext, context)
291264
auto rime = rime_get_api();
292265
auto session = Rime::Instance().sessionId();
@@ -302,9 +275,6 @@ Java_com_osfans_trime_core_Rime_getRimeContext(JNIEnv *env, jclass /* thiz */) {
302275

303276
extern "C" JNIEXPORT jobject JNICALL
304277
Java_com_osfans_trime_core_Rime_getRimeStatus(JNIEnv *env, jclass /* thiz */) {
305-
if (!is_rime_running()) {
306-
return nullptr;
307-
}
308278
RIME_STRUCT(RimeStatus, status)
309279
auto rime = rime_get_api();
310280
jobject obj = nullptr;
@@ -341,9 +311,6 @@ static bool is_save_option(const char *p) {
341311
// runtime options
342312
extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_setRimeOption(
343313
JNIEnv *env, jclass /* thiz */, jstring option, jboolean value) {
344-
if (!is_rime_running()) {
345-
return;
346-
}
347314
auto rime = rime_get_api();
348315
RimeConfig user = {nullptr};
349316
auto opt = CString(env, option);
@@ -361,9 +328,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_setRimeOption(
361328
extern "C" JNIEXPORT jboolean JNICALL
362329
Java_com_osfans_trime_core_Rime_getRimeOption(JNIEnv *env, jclass /* thiz */,
363330
jstring option) {
364-
if (!is_rime_running()) {
365-
return false;
366-
}
367331
return Rime::Instance().getOption(CString(env, option));
368332
}
369333

@@ -381,9 +345,6 @@ Java_com_osfans_trime_core_Rime_getRimeSchemaList(JNIEnv *env,
381345
extern "C" JNIEXPORT jstring JNICALL
382346
Java_com_osfans_trime_core_Rime_getCurrentRimeSchema(JNIEnv *env,
383347
jclass /* thiz */) {
384-
if (!is_rime_running()) {
385-
return env->NewStringUTF("");
386-
}
387348
return env->NewStringUTF(Rime::Instance().currentSchemaId().c_str());
388349
}
389350

@@ -407,84 +368,57 @@ extern "C" JNIEXPORT jboolean JNICALL
407368
Java_com_osfans_trime_core_Rime_simulateRimeKeySequence(JNIEnv *env,
408369
jclass /* thiz */,
409370
jstring key_sequence) {
410-
if (!is_rime_running()) {
411-
return false;
412-
}
413371
return Rime::Instance().simulateKeySequence(CString(env, key_sequence));
414372
}
415373

416374
extern "C" JNIEXPORT jstring JNICALL
417375
Java_com_osfans_trime_core_Rime_getRimeRawInput(JNIEnv *env,
418376
jclass /* thiz */) {
419-
if (!is_rime_running()) {
420-
return env->NewStringUTF("");
421-
}
422377
return env->NewStringUTF(Rime::Instance().rawInput().data());
423378
}
424379

425380
extern "C" JNIEXPORT jint JNICALL
426381
Java_com_osfans_trime_core_Rime_getRimeCaretPos(JNIEnv *env,
427382
jclass /* thiz */) {
428-
if (!is_rime_running()) {
429-
return -1;
430-
}
431383
return static_cast<jint>(Rime::Instance().caretPosition());
432384
}
433385

434386
extern "C" JNIEXPORT void JNICALL
435387
Java_com_osfans_trime_core_Rime_setRimeCaretPos(JNIEnv *env, jclass /* thiz */,
436388
jint caret_pos) {
437-
if (!is_rime_running()) {
438-
return;
439-
}
440389
Rime::Instance().setCaretPosition(caret_pos);
441390
}
442391

443392
extern "C" JNIEXPORT jboolean JNICALL
444393
Java_com_osfans_trime_core_Rime_selectRimeCandidateOnCurrentPage(
445394
JNIEnv *env, jclass /* thiz */, jint index) {
446-
if (!is_rime_running()) {
447-
return false;
448-
}
449395
return Rime::Instance().selectCandidateOnCurrentPage(index);
450396
}
451397

452398
extern "C" JNIEXPORT jboolean JNICALL
453399
Java_com_osfans_trime_core_Rime_deleteRimeCandidateOnCurrentPage(
454400
JNIEnv *env, jclass /* thiz */, jint index) {
455-
if (!is_rime_running()) {
456-
return false;
457-
}
458401
return Rime::Instance().deleteCandidateOnCurrentPage(index);
459402
}
460403

461404
extern "C" JNIEXPORT jboolean JNICALL
462405
Java_com_osfans_trime_core_Rime_selectRimeCandidate(JNIEnv *env,
463406
jclass /* thiz */,
464407
jint index) {
465-
if (!is_rime_running()) {
466-
return false;
467-
}
468408
return Rime::Instance().selectCandidate(index);
469409
}
470410

471411
extern "C" JNIEXPORT jboolean JNICALL
472412
Java_com_osfans_trime_core_Rime_forgetRimeCandidate(JNIEnv *env,
473413
jclass /* thiz */,
474414
jint index) {
475-
if (!is_rime_running()) {
476-
return false;
477-
}
478415
return Rime::Instance().forgetCandidate(index);
479416
}
480417

481418
extern "C" JNIEXPORT jobjectArray JNICALL
482419
Java_com_osfans_trime_core_Rime_getRimeCandidates(JNIEnv *env, jclass clazz,
483420
jint start_index,
484421
jint limit) {
485-
if (!is_rime_running()) {
486-
return nullptr;
487-
}
488422
auto candidates = Rime::Instance().getCandidates(start_index, limit);
489423
int size = static_cast<int>(candidates.size());
490424
jobjectArray array =

0 commit comments

Comments
 (0)