Skip to content

Commit 94ad8bc

Browse files
committed
refactor(jni): use std::string_view as more as possible
1 parent c45e16a commit 94ad8bc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ class Rime {
8888

8989
RIME_PROTO_OBJ statusProto() { return proto->status_proto(session); }
9090

91-
void setOption(const std::string &key, bool value) {
92-
rime->set_option(session, key.c_str(), value);
91+
void setOption(std::string_view key, bool value) {
92+
rime->set_option(session, key.data(), value);
9393
}
9494

95-
bool getOption(const std::string &key) {
96-
return rime->get_option(session, key.c_str());
95+
bool getOption(std::string_view key) {
96+
return rime->get_option(session, key.data());
9797
}
9898

9999
std::string currentSchemaId() {
@@ -112,8 +112,8 @@ class Rime {
112112
return std::move(result);
113113
}
114114

115-
bool selectSchema(const std::string &schemaId) {
116-
return rime->select_schema(session, schemaId.c_str());
115+
bool selectSchema(std::string_view schemaId) {
116+
return rime->select_schema(session, schemaId.data());
117117
}
118118

119119
std::string rawInput() { return rime->get_input(session); }
@@ -282,13 +282,13 @@ Java_com_osfans_trime_core_Rime_getRimeStatus(JNIEnv *env, jclass /* thiz */) {
282282
// runtime options
283283
extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_setRimeOption(
284284
JNIEnv *env, jclass /* thiz */, jstring option, jboolean value) {
285-
Rime::Instance().setOption(CString(env, option), value);
285+
Rime::Instance().setOption(*CString(env, option), value);
286286
}
287287

288288
extern "C" JNIEXPORT jboolean JNICALL
289289
Java_com_osfans_trime_core_Rime_getRimeOption(JNIEnv *env, jclass /* thiz */,
290290
jstring option) {
291-
return Rime::Instance().getOption(CString(env, option));
291+
return Rime::Instance().getOption(*CString(env, option));
292292
}
293293

294294
extern "C" JNIEXPORT jobjectArray JNICALL
@@ -306,7 +306,7 @@ Java_com_osfans_trime_core_Rime_getCurrentRimeSchema(JNIEnv *env,
306306
extern "C" JNIEXPORT jboolean JNICALL
307307
Java_com_osfans_trime_core_Rime_selectRimeSchema(JNIEnv *env, jclass /* thiz */,
308308
jstring schema_id) {
309-
return Rime::Instance().selectSchema(CString(env, schema_id));
309+
return Rime::Instance().selectSchema(*CString(env, schema_id));
310310
}
311311

312312
// testing

0 commit comments

Comments
 (0)