diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/Numbers.md b/ArkTS_high_performance_segment/entry/src/main/ets/segment/Numbers.md new file mode 100644 index 0000000000000000000000000000000000000000..1fb9ad51f74e133749fd026e9d594a32fb4861b8 --- /dev/null +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/Numbers.md @@ -0,0 +1,51 @@ +// [Start import_nested_error] +// Numbers.ets +export const One: number = 1; + +// ... +// Multi-layer export nested here * + +// Utils.ets +export * from './Numbers'; + +// SecondPage.ets +export * from './Utils'; + +// Index.ets +import * from './SecondPage'; +// [End import_nested_error] + +// [Start import_nested] +// Numbers.ets +export const One: number = 1; + +// Index.ets +import { One } from './Numbers'; +// [End import_nested] + +// [Start reduced_import_error] +// Index.ets +import * as nm from '../utils/Numbers'; // The import * method is not recommended +hilog.info(0x0000, 'testTag', '%{public}d', nm.One); // Only the variable One is used here +// Numbers.ets +export const One: number = 1; +export const Two: number = 2; +// ... +// 100,000 pieces of data are omitted here +// [End reduced_import_error] + +// [Start reduced_import] +// Index.ets +import { One } as nm from '../utils/Numbers'; // It is recommended to reference variables on demand +hilog.info(0x0000, 'testTag', '%{public}d', One); // Only the variable One is used here +// Numbers.ets +export const One: number = 1; +export const Two: number = 2; +// ... +// 100,000 pieces of data are omitted here +// [End reduced_import] + +// [Start hdc_shell] +hdc shell param set persist.ark.properties 0x200105c +hdc shell reboot +// [End hdc_shell] \ No newline at end of file diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets index 2ecf84f95367104042c731c8c8b4e23d478d6f50..1f745f666a5690fb1ab650409ba2f9226656208b 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets @@ -1,5 +1,5 @@ // [Start Counter_example1] -// 该变量在后续过程并未发生改变,建议声明为常量 +// The variable does not change in the subsequent process. It is recommended to declare it as a constant let PRICE = 10000; function getPrice() { @@ -10,7 +10,7 @@ class ClassA { propA: string = 'propA' } -// 该引用类型的变量在后续过程变量地址并未发生改变,仅修改了变量的属性,本例中的let建议改为const +// The variable address of the reference type is not changed in the subsequent process, only the variable property is modified. In this example, it is recommended to change the value of let to const let classA: ClassA = new ClassA(); classA.propA = 'Property A'; // [End Counter_example1] @@ -37,7 +37,7 @@ class Time { function getDay(year: number): number { let totalDays: number = 348; for (let index: number = 0x8000; index > 0x8; index >>= 1) { - // 此处会多次对Time的INFO及START进行查找,并且每次查找出来的值是相同的 + // The value of Time is the same as that of the value of the value of the value of the value of the time totalDays += ((Time.INFO[year - Time.START] & index) !== 0) ? 1 : 0; } return totalDays; @@ -47,24 +47,23 @@ function getDay(year: number): number { // [Start Counter_example3] class Counter { - // 没有设置访问修饰符默认为public + // The access modifier is not set. The default value is public count: number = 0; - getCount(): number { return this.count; } } -// 访问时 +// When accessing const counter:Counter = new Counter(); -console.info(counter.count.toString()); // 可以通过实例访问 +console.info(counter.count.toString()); // can be accessed through the instance console.info(counter.getCount().toString()); // [End Counter_example3] // [Start Counter_example4] -const array1 = new Array(1, 2, 3); // 针对这一场景,建议不要使用new Array(1, 2, 3) -const array2 = new Array(4, 5, 6); // 针对这一场景,建议不要使用new Array(4, 5, 6) +const array1 = new Array(1, 2, 3); // For this scenario, it is recommended that you do not use new Array (1, 2, 3) +const array2 = new Array(4, 5, 6); // For this scenario, it is recommended that new Array (4, 5, 6) be not used const res = new Array(3); for (let i = 0; i < 3; i++) { res[i] = array1[i] + array2[i]; @@ -77,7 +76,7 @@ class InfoUtil { if (t1 === t2) { return ""; } - // 此处使用Record普通对象作为容器 + // The common Record object is used as the container let info: Record = {}; this.setInfo(info); let t3 = info[t2]; @@ -86,7 +85,7 @@ class InfoUtil { setInfo(info: Record) { - // 接口内部实际上进行的是map的操作 + //The interface actually performs the map operation info.aaa = 'aaa'; info.bbb = 'bbb'; info.ccc = 'ccc'; @@ -95,11 +94,11 @@ class InfoUtil { // [End Counter_example5] // [Start Counter_example6] -// 下面情形会变成稀疏数组 -// 1. 直接分配100000大小的数组,虚拟机会处理成用hash表来存储元素 +// The following case will become a sparse array +// 1. Directly allocate an array with a size of 100,000, and the virtual machine processes it as a hash table to store elements let count = 100000; let result: number[] = new Array(count); -// 2. 分配数组之后直接,在9999处初始化,会变成稀疏数组 +// 2. After allocating the array, it will become a sparse array directly, initialize at 9999 result[9999] = 0; // [End Counter_example6] @@ -108,7 +107,7 @@ result[9999] = 0; const arr:number[] = [0, 1, 2]; function foo() { arr[0] = 1; - // arr 保持对外部变量的使用 + // arr keeps the use of external variables return arr[0] + arr[1]; } let aFoo = foo; diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets index 48eebe4d43b340ce73ac0869a2123803207025aa..cd096f2dd8c83bb6adfc27315aa5ce57114795c0 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets @@ -2,11 +2,11 @@ // app.ets import { getObject, TestA } from './segment'; -let obj: TestA = getObject(123); // 显式引入标注类型 +let obj: TestA = getObject(123); // Explicitly introduce the label type // [End Case4] // [Start Case] -const PRICE = 10000; // 常量声明为基础类型时,其内容不可改变 +const PRICE = 10000; // When a constant is declared as a base type, its content cannot be changed function getPrice() { return PRICE; @@ -16,14 +16,15 @@ class ClassA { propA: string = 'propA' } -// 常量声明为引用类型时,其地址不可改变,但可以改变属性 +// When a constant is declared as a reference type, its address cannot be changed, but its properties can be changed const classA: ClassA = new ClassA(); classA.propA = 'Property A'; + // [End Case] // [Start Case2] function calAddSum(addNum: number): number { - // count预期是int,不要声明成undefined/null或0.0,直接初始化为0 + // count is expected to be int, do not declare it as undefined/null or 0.0, directly initialize it to 0 let count = 0; count += addNum; return count; @@ -31,16 +32,15 @@ function calAddSum(addNum: number): number { // [End Case2] // [Start Case5] -// 优化后代码 +// Code after optimization class Time { static START: number = 1987; static INFO: number[] = [2001, 2002, 2003, 2004, 2005, 2006]; } - function getDay(year: number): number { let totalDays: number = 348; - // 从循环中提取不变量 + // Extract invariants from the loop const info = Time.INFO[year - Time.START]; for (let index: number = 0x8000; index > 0x8; index >>= 1) { if ((info & index) !== 0) { @@ -53,22 +53,24 @@ function getDay(year: number): number { // [Start Case6] class Counter { - // 设置访问修饰符为private + // Set the access modifier to private private count: number = 0; - public getCount(): number { return this.count; } } -// 访问时 -const counter:Counter = new Counter(); + +// When accessing +const counter: Counter = new Counter(); let res = counter.getCount(); // [End Case6] // [Start Case7] -const typedArray1 = new Int8Array([1, 2, 3]); // 针对这一场景,建议不要使用new Array([1, 2, 3]) -const typedArray2 = new Int8Array([4, 5, 6]); // 针对这一场景,建议不要使用new Array([4, 5, 6]) +const typedArray1 = + new Int8Array([1, 2, 3]); // For this scenario, it is recommended that you do not use new Array ([1, 2, 3]) +const typedArray2 = + new Int8Array([4, 5, 6]); // For this scenario, it is recommended that you do not use new Array ([4, 5, 6]) const res1 = new Int8Array(3); for (let i = 0; i < 3; i++) { res1[i] = typedArray1[i] + typedArray2[i]; @@ -77,7 +79,8 @@ for (let i = 0; i < 3; i++) { // [Start Case9] let arr: number[] = [0, 1, 2]; -// 改为通过参数传递 + +// Change to pass by parameters function foo(array: Array): number { array[0] = 1; return array[0] + array[1]; diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets index 55e9ee36ec7edefa293346687d3d318c2c0ac047..f5d371a8d16ce19091997e3338245d269c04a198 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets @@ -6,7 +6,7 @@ class InfoUtil { if (t1 === t2) { return ""; } - // 此处改为使用HashMap进行读写操作 + // The HashMap is used for read and write operations let info: HashMap = new HashMap(); this.setInfo(info); let t3 = info.get(t2); diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets index 01f7daae60235220b38c095d9e42594a162eb86a..f9dc50322a29a0e69e095917dbb257413bc83623 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets @@ -1,5 +1,5 @@ // [Start Case10] -// A为任意可以被引入的ets文件 +// A is any ets file that can be imported import { A } from "./A" @@ -8,9 +8,9 @@ import { A } from "./A" struct Index { build() { RelativeContainer() { - Button('点击执行A') + Button('Click to perform A') .onClick(() => { - console.log('执行A' + A) + console.log('Perform A' + A) }) } // ... diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets index 7f4cc7ed504bfc3f21409b8f7c0d44ac166579ef..30828c874a1128fcf4a6d2045494a859b1c384f5 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets @@ -6,9 +6,9 @@ import lazy { A } from "./A" struct Index { build() { RelativeContainer() { - Button('点击执行A') + Button('Click to perform A') .onClick(() => { - console.log('执行A' + A) + console.log('Perform A' + A) }) } .height('100%')