Skip to content

Commit d37e6c9

Browse files
authored
ohos code optimization (#20856)
Signed-off-by: 冰冰冰 <[email protected]>
1 parent f959404 commit d37e6c9

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

cocos/platform/CCApplicationProtocol.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CC_DLL ApplicationProtocol
5959
// OS_TIZEN, /**< Tizen */
6060
// OS_WINRT, /**< Windows Runtime Applications */
6161
// OS_WP8 /**< Windows Phone 8 Applications */
62-
OS_HARMONY_NEXT /**< OPENHARMONY */
62+
OS_HARMONY_NEXT /**< OS_HARMONY_NEXT */
6363
};
6464

6565
/**

cocos/platform/ohos/napi/modules/InputNapi.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,25 @@ napi_value InputNapi::textFieldTTFOnChangeCB(napi_env env, napi_callback_info in
143143
char text[2560] = {0};
144144
NAPI_CALL(env, napi_get_value_string_utf8(env, args[0], text, 2560, &textLen));
145145

146-
// 优化: 使用string_view避免不必要的字符串拷贝
146+
// Using string-view to avoid unnecessary string copying
147147
std::string_view oldView(oldContent);
148148
std::string_view newView(text, textLen);
149149

150-
// 找到第一个不同的字符位置
150+
// Find the first different character position
151151
size_t commonPrefixLen = 0;
152152
const size_t minLen = std::min(oldView.length(), newView.length());
153153
while (commonPrefixLen < minLen && oldView[commonPrefixLen] == newView[commonPrefixLen]) {
154154
commonPrefixLen++;
155155
}
156156

157-
// 删除差异后的旧内容字符
157+
// Delete old content characters after differences
158158
const size_t charsToDelete = oldView.length() - commonPrefixLen;
159159
const size_t deleteOperations = [&]() {
160160
size_t count = 0;
161161
size_t pos = oldView. length() - 1;
162162
size_t remaining = charsToDelete;
163163
while (remaining > 0) {
164-
// 检查UTF-8中文字符(0xE0-0xEF开头的3字节字符)
164+
// Check UTF-8 Chinese characters (3-byte characters starting with 0xE0-0xEF)
165165
bool isChineseChar = (pos >= 2 &&
166166
(unsigned char)oldView [pos-2] >= 0xE0 &&
167167
(unsigned char)oldView [pos-2] <= 0xEF);
@@ -171,12 +171,12 @@ napi_value InputNapi::textFieldTTFOnChangeCB(napi_env env, napi_callback_info in
171171
}
172172
return count;
173173
}();
174-
//批量删除字符
174+
// Batch delete characters
175175
for (size_t i = 0; i < deleteOperations; i++) {
176176
dispatcher->dispatchDeleteBackward();
177177
}
178178
const size_t insertLen = newView.length() - commonPrefixLen;
179-
// 插入差异后的新字符
179+
// Insert new characters after differences
180180
if ( insertLen > 0) {
181181
const char* newText = text + commonPrefixLen;
182182
CCLOG("textFieldTTFOnChangeCB: Inserting %zu characters: %s", insertLen, newText);

tests/cpp-tests/proj.ohos/entry/src/main/ets/pages/Index.ets

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ struct Index {
7474
buttons: [
7575
{
7676
text: '取消',
77-
// 颜色可自定义
77+
// Color can be customized
7878
color: '#000000'
7979
},
8080
{
8181
text: '确认',
82-
// 颜色可自定义
82+
// Color can be customized
8383
color: '#000000'
8484
}
8585
],

tests/lua-tests/project/proj.ohos/entry/src/main/ets/pages/Index.ets

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ struct Index {
7474
buttons: [
7575
{
7676
text: '取消',
77-
// 颜色可自定义
77+
// Color can be customized
7878
color: '#000000'
7979
},
8080
{
8181
text: '确认',
82-
// 颜色可自定义
82+
// Color can be customized
8383
color: '#000000'
8484
}
8585
],

0 commit comments

Comments
 (0)