代码拉取完成,页面将自动刷新
【任务描述】
modified TS associative container class
此部分用TS实现container容器,依赖于TS的知识,以及对接口定义的了解
代码实现主要在/base/compileruntime/js_util_module/container目录下,实现代码主要涉及的文件
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);
}
}
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
以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,
};
}
登录 后才可以发表评论