当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
7 Star 3 Fork 38

OpenHarmony / js_util_module
关闭

 / 详情

Add the entire TS container class

已完成
任务
创建于  
2022-01-17 20:48

【任务描述】
Add the entire TS container class
此部分用TS实现container容器,依赖于TS的知识,以及对接口定义的了解

1.目录结构

代码实现主要在/base/compileruntime/js_util_module/container目录下,实现代码主要涉及的文件

base/compileruntime/js_util_module/container/arraylist  
base/compileruntime/js_util_module/container/vector
base/compileruntime/js_util_module/container/queue
base/compileruntime/js_util_module/container/deque
base/compileruntime/js_util_module/container/list
base/compileruntime/js_util_module/container/linkedlist
base/compileruntime/js_util_module/container/stack
base/compileruntime/js_util_module/container/treemap  
base/compileruntime/js_util_module/container/treeset
base/compileruntime/js_util_module/container/hashmap
base/compileruntime/js_util_module/container/hashset
base/compileruntime/js_util_module/container/plainarray
base/compileruntime/js_util_module/container/lightweightmap
base/compileruntime/js_util_module/container/lightweightset
base/compileruntime/js_util_module/container/struct


base/compileruntime/js_util_module/container/struct的struct.ts文件把所有的结构体(如红黑树RBtree_class)都抽取出来,实现结构体复用,减少代码冗余
涉及文件如下,大部分文件需要按照已有实现增加一个配置文件native_module_lightweightset.cpp

 /*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "utils/log.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"

extern const char _binary_js_lightweightset_js_start[];
extern const char _binary_js_lightweightset_js_end[];
extern const char _binary_lightweightset_abc_start[];
extern const char _binary_lightweightset_abc_end[];

namespace OHOS::Util {
static napi_value LightWeightSetInit(napi_env env, napi_value exports)
{
    return exports;
}

extern "C"
__attribute__((visibility("default"))) void NAPI_lightweightset_GetJSCode(const char **buf, int *bufLen)
{
    if (buf != nullptr) {
        *buf = _binary_js_lightweightset_js_start;
    }

    if (bufLen != nullptr) {
        *bufLen = _binary_js_lightweightset_js_end - _binary_js_lightweightset_js_start;
    }
}

extern "C"
__attribute__((visibility("default"))) void NAPI_lightweightset_GetABCCode(const char** buf, int* buflen)
{
    if (buf != nullptr) {
        *buf = _binary_lightweightset_abc_start;
    }
    if (buflen != nullptr) {
        *buflen = _binary_lightweightset_abc_end - _binary_lightweightset_abc_start;
    }
}

static napi_module lightWeightSetModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = LightWeightSetInit,
    .nm_modname = "LightWeightSet",
    .nm_priv = ((void*)0),
    .reserved = { 0 },
};

extern "C" __attribute__ ((constructor)) void RegisterModule()
{
    napi_module_register(&lightWeightSetModule);
}
}

2.在container/BUILD.gn文件中按照已有实现增加相应的容器类名称就可以

 container_names = [
 20   "arraylist",
 21   "deque",
 22   "queue",
 23   "vector",
 24   "linkedlist",
 25   "list",
 26   "stack",
 27   "treemap",
 28   "treeset",
 29   "hashmap",
 30   "hashset",
 31   "lightweightmap",
 32   "lightweightset",
 33   "plainarray"
 34 ]
 35 

3.TS侧使用

以plainarray为例,TS侧通过如下代码决定是否初始化Ark侧PlainArray。

let flag = false;
let fastPlainArray: any = undefined;
let arkPritvate = globalThis["ArkPrivate"] || undefined;
if (arkPritvate !== undefined) {
  fastPlainArray = arkPritvate.Load(arkPritvate.PlainArray);
} else {
  flag = true;
}
if (flag) {
    ...
 Object.freeze(PlainArray);
  fastPlainArray = PlainArray;
}
export default {
  PlainArray: fastPlainArray,
};

}

评论 (0)

wangyong 创建了任务
wangyong 修改了描述
gonggong 任务状态待办的 修改为进行中
gonggong 任务状态进行中 修改为已完成
xliu 任务状态已完成 修改为进行中
wangyong 任务状态进行中 修改为已完成
展开全部操作日志

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(1)
1
https://gitee.com/openharmony/js_util_module.git
git@gitee.com:openharmony/js_util_module.git
openharmony
js_util_module
js_util_module

搜索帮助

53164aa7 5694891 3bd8fe86 5694891