From 5ab6c6c1e762b3039bd81207f22cab1fe74afd7c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 18 Oct 2016 21:26:46 +0900 Subject: [PATCH] Reduce unnecessary string comparison in Web IME Change-Id: I89fb038df0a6b4d59dd13f3eee1b0b4b1a4ae8ba Signed-off-by: Jihoon Kim --- src/legacy_support/websocket.cpp | 41 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/legacy_support/websocket.cpp b/src/legacy_support/websocket.cpp index 3814e5f..59f00c3 100644 --- a/src/legacy_support/websocket.cpp +++ b/src/legacy_support/websocket.cpp @@ -934,8 +934,7 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) } } log(str.c_str()); - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_COMMIT_STRING]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_COMMIT_STRING]) == 0) { send_key_event(0xff6b, 0); // Temporarily reset keyboard engine std::string str = ""; @@ -946,8 +945,7 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) } } commit_string(str.c_str()); - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_UPDATE_PREEDIT_STRING]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_UPDATE_PREEDIT_STRING]) == 0) { std::string str = ""; for (unsigned int loop = 0;loop < message.values.size();loop++) { str += message.values.at(loop).c_str(); @@ -956,24 +954,27 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) } } update_preedit_string(str.c_str()); - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SEND_KEY_EVENT]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SEND_KEY_EVENT]) == 0) { if (message.values.size() == 1) { send_key_event(atoi(message.values.at(0).c_str()), 0); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SET_KEYBOARD_SIZES]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SET_KEYBOARD_SIZES]) == 0) { LOGD("ISE_MESSAGE_COMMAND_SET_KEYBOARD_SIZES"); if (message.values.size() == 4) { + int portrait_width, portrait_height; + int landscape_width, landscape_height; + + portrait_width = atoi(message.values.at(0).c_str()); + portrait_height = atoi(message.values.at(1).c_str()); + landscape_width = atoi(message.values.at(2).c_str()); + landscape_height = atoi(message.values.at(3).c_str()); + LOGD("ISE_MESSAGE_COMMAND_SET_KEYBOARD_SIZES : %d %d %d %d", - atoi(message.values.at(0).c_str()), atoi(message.values.at(1).c_str()), - atoi(message.values.at(2).c_str()), atoi(message.values.at(3).c_str())); + portrait_width, portrait_height, landscape_width, landscape_height); set_keyboard_sizes( - atoi(message.values.at(0).c_str()), atoi(message.values.at(1).c_str()), - atoi(message.values.at(2).c_str()), atoi(message.values.at(3).c_str())); + portrait_width, portrait_height, landscape_width, landscape_height); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SET_SELECTION]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_SET_SELECTION]) == 0) { LOGD("ISE_MESSAGE_COMMAND_SET_SELECTION"); if (message.values.size() == 2) { LOGD("ISE_MESSAGE_COMMAND_SET_SELECTION : %d %d", @@ -981,13 +982,11 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) set_selection( atoi(message.values.at(0).c_str()), atoi(message.values.at(1).c_str())); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_SELECTION]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_SELECTION]) == 0) { if (message.values.size() == 0) { get_selection(); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_SURROUNDING_TEXT]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_SURROUNDING_TEXT]) == 0) { LOGD("ISE_MESSAGE_COMMAND_GET_SURROUNDING_TEXT"); if (message.values.size() == 2) { LOGD("ISE_MESSAGE_COMMAND_GET_SURROUNDING_TEXT : %d %d", @@ -995,8 +994,7 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) get_surrounding_text( atoi(message.values.at(0).c_str()), atoi(message.values.at(1).c_str())); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_DELETE_SURROUNDING_TEXT]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_DELETE_SURROUNDING_TEXT]) == 0) { LOGD("ISE_MESSAGE_COMMAND_DELETE_SURROUNDING_TEXT"); if (message.values.size() == 2) { LOGD("ISE_MESSAGE_COMMAND_DELETE_SURROUNDING_TEXT : %d %d", @@ -1004,8 +1002,7 @@ void CWebHelperAgentWebSocket::handle_recved_message(ISE_MESSAGE &message) delete_surrounding_text( atoi(message.values.at(0).c_str()), atoi(message.values.at(1).c_str())); } - } - if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_LOGIN]) == 0) { + } else if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_LOGIN]) == 0) { if (g_ws_server_context) { lws_callback_on_writable_all_protocol(g_ws_server_context, &protocols[PROTOCOL_KEYBOARD]); } else { -- 2.7.4