Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix redundant conversion from slice to map/list #252

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit"
version = "0.9.3"
version = "0.9.4"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion ts-src/js-list.mts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export class CalcitSliceList {
start: number;
end: number;
cachedHash: Hash;
/** reference to converted list */
cachedTreeListRef: CalcitList;
constructor(value: Array<CalcitValue>) {
if (value == null) {
value = []; // dirty, better handled from outside
Expand All @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion ts-src/js-map.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
Expand Down
Loading