diff --git a/Cargo.lock b/Cargo.lock index 9574549..8d47dc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,7 +76,7 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "calcit" -version = "0.9.3" +version = "0.9.4" dependencies = [ "argh", "cirru_edn", diff --git a/Cargo.toml b/Cargo.toml index f4cc615..932a2dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit" -version = "0.9.3" +version = "0.9.4" authors = ["jiyinyiyong "] edition = "2021" license = "MIT" diff --git a/package.json b/package.json index 93f45c6..3951f5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@calcit/procs", - "version": "0.9.3", + "version": "0.9.4", "main": "./lib/calcit.procs.mjs", "devDependencies": { "@types/node": "^22.1.0", diff --git a/ts-src/js-list.mts b/ts-src/js-list.mts index bbec863..a0ebbd3 100644 --- a/ts-src/js-list.mts +++ b/ts-src/js-list.mts @@ -123,6 +123,8 @@ export class CalcitSliceList { start: number; end: number; cachedHash: Hash; + /** reference to converted list */ + cachedTreeListRef: CalcitList; constructor(value: Array) { if (value == null) { value = []; // dirty, better handled from outside @@ -134,7 +136,12 @@ export class CalcitSliceList { this.end = value.length; } turnListMode(): CalcitList { - return new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end)); + if (this.cachedTreeListRef != null) { + return this.cachedTreeListRef; + } + let ret = new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end)); + this.cachedTreeListRef = ret; + return ret; } len() { return this.end - this.start; diff --git a/ts-src/js-map.mts b/ts-src/js-map.mts index 7e3fc28..b656f56 100644 --- a/ts-src/js-map.mts +++ b/ts-src/js-map.mts @@ -194,6 +194,8 @@ export class CalcitSliceMap { cachedHash: Hash; /** in arrayMode, only flatten values, instead of tree structure */ chunk: CalcitValue[]; + /** reference to generated HashMap in tree structure */ + cachedTreeMapRef?: CalcitMap; constructor(value: CalcitValue[]) { if (value == null) { this.chunk = []; @@ -203,14 +205,20 @@ export class CalcitSliceMap { throw new Error("unknown data for map"); } } + /** convert to tree map when needed, also cached in case converted over and over again */ turnMap(): CalcitMap { + if (this.cachedTreeMapRef != null) { + return this.cachedTreeMapRef; + } var dict: Array<[CalcitValue, CalcitValue]> = []; let halfLength = this.chunk.length >> 1; for (let idx = 0; idx < halfLength; idx++) { dict.push([this.chunk[idx << 1], this.chunk[(idx << 1) + 1]]); } let value = initTernaryTreeMapFromArray(dict); - return new CalcitMap(value); + let ret = new CalcitMap(value); + this.cachedTreeMapRef = ret; + return ret; } len() { return this.chunk.length >> 1;