@calcit/procs 0.9.16 → 0.9.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,7 @@ To use Calcit in GitHub Actions, try [setup-cr](https://github.com/calcit-lang/s
39
39
 
40
40
  ### Usage
41
41
 
42
- Snippets evaling:
42
+ Snippets evaluating:
43
43
 
44
44
  ```bash
45
45
  cr eval 'range 100'
@@ -97,36 +97,32 @@ export let getStringName = (x) => {
97
97
  };
98
98
  /** returns -1 when not found */
99
99
  export function findInFields(xs, y) {
100
- let lower = 0;
101
- let upper = xs.length - 1;
102
- while (upper - lower > 1) {
103
- let pos = (lower + upper) >> 1;
104
- let v = xs[pos];
105
- if (y.idx < v.idx) {
106
- upper = pos - 1;
100
+ let low = 0;
101
+ let high = xs.length - 1;
102
+ while (low <= high) {
103
+ const mid = Math.floor((low + high) / 2);
104
+ const midVal = xs[mid];
105
+ if (midVal.idx < y.idx) {
106
+ low = mid + 1;
107
107
  }
108
- else if (y.idx > v.idx) {
109
- lower = pos + 1;
108
+ else if (midVal.idx > y.idx) {
109
+ high = mid - 1;
110
110
  }
111
111
  else {
112
- return pos;
112
+ return mid;
113
113
  }
114
114
  }
115
- if (y === xs[lower])
116
- return lower;
117
- if (y === xs[upper])
118
- return upper;
119
115
  return -1;
120
116
  }
121
- var tagRegistery = {};
117
+ var tagRegistry = {};
122
118
  export let newTag = (content) => {
123
- let item = tagRegistery[content];
119
+ let item = tagRegistry[content];
124
120
  if (item != null) {
125
121
  return item;
126
122
  }
127
123
  else {
128
124
  let v = new CalcitTag(content);
129
- tagRegistery[content] = v;
125
+ tagRegistry[content] = v;
130
126
  return v;
131
127
  }
132
128
  };
@@ -554,23 +550,30 @@ export let _$n__$e_ = (x, y) => {
554
550
  return false;
555
551
  }
556
552
  let values = x.values();
553
+ let yValues = y.values();
554
+ // Optimize: create a Map for O(1) lookup instead of O(n) iteration
555
+ let yMap = new Map();
556
+ for (let idx = 0; idx < yValues.length; idx++) {
557
+ let yv = yValues[idx];
558
+ yMap.set(yv, true);
559
+ }
557
560
  for (let idx = 0; idx < values.length; idx++) {
558
561
  let v = values[idx];
559
562
  let found = false;
560
- // testing by doing iteration is O(n2), could be slow
561
- // but Set::contains does not satisfy here
562
- let yValues = y.values();
563
- for (let idx = 0; idx < yValues.length; idx++) {
564
- let yv = yValues[idx];
565
- if (_$n__$e_(v, yv)) {
566
- found = true;
567
- break;
568
- }
569
- }
570
- if (found) {
571
- continue;
563
+ // First try direct lookup for primitive values
564
+ if (yMap.has(v)) {
565
+ found = true;
572
566
  }
573
567
  else {
568
+ // Fallback to deep equality check for complex values
569
+ for (let yv of yValues) {
570
+ if (_$n__$e_(v, yv)) {
571
+ found = true;
572
+ break;
573
+ }
574
+ }
575
+ }
576
+ if (!found) {
574
577
  return false;
575
578
  }
576
579
  }
@@ -638,14 +638,10 @@ export let round_$q_ = (a) => {
638
638
  return a === Math.round(a);
639
639
  };
640
640
  export let _$n_str_$o_concat = (a, b) => {
641
- let buffer = "";
642
- if (a != null) {
643
- buffer += toString(a, false);
644
- }
645
- if (b != null) {
646
- buffer += toString(b, false);
647
- }
648
- return buffer;
641
+ // Optimize string concatenation by avoiding unnecessary toString calls
642
+ const aStr = a != null ? toString(a, false) : "";
643
+ const bStr = b != null ? toString(b, false) : "";
644
+ return aStr + bStr;
649
645
  };
650
646
  export let sort = (xs, f) => {
651
647
  if (xs == null) {
@@ -837,7 +833,7 @@ export let parse_float = (x) => {
837
833
  export let trim = (x, c) => {
838
834
  if (c != null) {
839
835
  if (c.length !== 1) {
840
- throw new Error("Expceted c of a character");
836
+ throw new Error("Expected c of a character");
841
837
  }
842
838
  var buffer = x;
843
839
  var size = buffer.length;
package/lib/js-cirru.mjs CHANGED
@@ -280,7 +280,7 @@ export let extract_cirru_edn = (x, options) => {
280
280
  }
281
281
  }
282
282
  else {
283
- throw new Error(`Expected pairs for reocrd, got: ${pair}`);
283
+ throw new Error(`Expected pairs for record, got: ${pair}`);
284
284
  }
285
285
  });
286
286
  entries.sort((a, b) => {
package/lib/js-list.mjs CHANGED
@@ -313,7 +313,7 @@ export let foldl = function (xs, acc, f) {
313
313
  });
314
314
  return result;
315
315
  }
316
- throw new Error("Unknow data for foldl");
316
+ throw new Error("Unknown data for foldl");
317
317
  };
318
318
  export let foldl_shortcut = function (xs, acc, v0, f) {
319
319
  if (arguments.length !== 4) {
@@ -411,7 +411,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
411
411
  }
412
412
  return v0;
413
413
  }
414
- throw new Error("Unknow data for foldl-shortcut");
414
+ throw new Error("Unknown data for foldl-shortcut");
415
415
  };
416
416
  export let foldr_shortcut = function (xs, acc, v0, f) {
417
417
  if (arguments.length !== 4) {
@@ -442,5 +442,5 @@ export let foldr_shortcut = function (xs, acc, v0, f) {
442
442
  }
443
443
  return v0;
444
444
  }
445
- throw new Error("Unknow data for foldr-shortcut, expected only list");
445
+ throw new Error("Unknown data for foldr-shortcut, expected only list");
446
446
  };
package/lib/js-map.mjs CHANGED
@@ -154,7 +154,7 @@ export class CalcitMap {
154
154
  }
155
155
  return new CalcitSet(ret);
156
156
  }
157
- /** detecthing in custom formatter */
157
+ /** detecting in custom formatter */
158
158
  nestedDataInChildren() {
159
159
  let pairs = this.pairs();
160
160
  for (let idx = 0; idx < pairs.length; idx++) {
@@ -365,7 +365,7 @@ export class CalcitSliceMap {
365
365
  }
366
366
  return new CalcitSet(ret);
367
367
  }
368
- /** detecthing in custom formatter */
368
+ /** detecting in custom formatter */
369
369
  nestedDataInChildren() {
370
370
  let pairs = this.pairs();
371
371
  for (let idx = 0; idx < pairs.length; idx++) {
package/lib/js-primes.mjs CHANGED
@@ -40,7 +40,7 @@ var PseudoTypeIndex;
40
40
  PseudoTypeIndex[PseudoTypeIndex["cirru_quote"] = 14] = "cirru_quote";
41
41
  })(PseudoTypeIndex || (PseudoTypeIndex = {}));
42
42
  let typeAsInt = (x) => {
43
- // based on order used in Ord traint
43
+ // based on order used in Ord trait
44
44
  if (x == null)
45
45
  return PseudoTypeIndex.nil;
46
46
  let t = typeof x;
package/lib/js-record.mjs CHANGED
@@ -61,11 +61,13 @@ export class CalcitRecord {
61
61
  return idx >= 0;
62
62
  }
63
63
  toString(disableJsDataWarning = false) {
64
- let ret = "(%{} " + this.name;
64
+ // Optimize string building using array join instead of concatenation
65
+ const parts = ["(%{} ", this.name.toString()];
65
66
  for (let idx = 0; idx < this.fields.length; idx++) {
66
- ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
67
+ parts.push(" (", this.fields[idx].toString(), " ", toString(this.values[idx], true, disableJsDataWarning), ")");
67
68
  }
68
- return ret + ")";
69
+ parts.push(")");
70
+ return parts.join("");
69
71
  }
70
72
  withClass(klass) {
71
73
  if (klass instanceof CalcitRecord) {
package/lib/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
- "@types/node": "^22.15.24",
7
- "typescript": "^5.8.3"
6
+ "@types/node": "^24.1.0",
7
+ "typescript": "^5.9.2"
8
8
  },
9
9
  "scripts": {
10
10
  "compile": "rm -rfv lib/* && tsc",
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/calcit-lang/calcit"
23
23
  },
24
24
  "dependencies": {
25
- "@calcit/ternary-tree": "0.0.24",
25
+ "@calcit/ternary-tree": "0.0.25",
26
26
  "@cirru/parser.ts": "^0.0.6",
27
27
  "@cirru/writer.ts": "^0.1.5"
28
28
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
- "@types/node": "^22.15.24",
7
- "typescript": "^5.8.3"
6
+ "@types/node": "^24.1.0",
7
+ "typescript": "^5.9.2"
8
8
  },
9
9
  "scripts": {
10
10
  "compile": "rm -rfv lib/* && tsc",
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/calcit-lang/calcit"
23
23
  },
24
24
  "dependencies": {
25
- "@calcit/ternary-tree": "0.0.24",
25
+ "@calcit/ternary-tree": "0.0.25",
26
26
  "@cirru/parser.ts": "^0.0.6",
27
27
  "@cirru/writer.ts": "^0.1.5"
28
28
  }
@@ -118,35 +118,32 @@ export let getStringName = (x: CalcitValue): string => {
118
118
 
119
119
  /** returns -1 when not found */
120
120
  export function findInFields(xs: Array<CalcitTag>, y: CalcitTag): number {
121
- let lower = 0;
122
- let upper = xs.length - 1;
123
-
124
- while (upper - lower > 1) {
125
- let pos = (lower + upper) >> 1;
126
- let v = xs[pos];
127
- if (y.idx < v.idx) {
128
- upper = pos - 1;
129
- } else if (y.idx > v.idx) {
130
- lower = pos + 1;
121
+ let low = 0;
122
+ let high = xs.length - 1;
123
+
124
+ while (low <= high) {
125
+ const mid = Math.floor((low + high) / 2);
126
+ const midVal = xs[mid];
127
+ if (midVal.idx < y.idx) {
128
+ low = mid + 1;
129
+ } else if (midVal.idx > y.idx) {
130
+ high = mid - 1;
131
131
  } else {
132
- return pos;
132
+ return mid;
133
133
  }
134
134
  }
135
-
136
- if (y === xs[lower]) return lower;
137
- if (y === xs[upper]) return upper;
138
135
  return -1;
139
136
  }
140
137
 
141
- var tagRegistery: Record<string, CalcitTag> = {};
138
+ var tagRegistry: Record<string, CalcitTag> = {};
142
139
 
143
140
  export let newTag = (content: string) => {
144
- let item = tagRegistery[content];
141
+ let item = tagRegistry[content];
145
142
  if (item != null) {
146
143
  return item;
147
144
  } else {
148
145
  let v = new CalcitTag(content);
149
- tagRegistery[content] = v;
146
+ tagRegistry[content] = v;
150
147
  return v;
151
148
  }
152
149
  };
@@ -591,22 +588,30 @@ export let _$n__$e_ = (x: CalcitValue, y: CalcitValue): boolean => {
591
588
  return false;
592
589
  }
593
590
  let values = x.values();
591
+ let yValues = y.values();
592
+ // Optimize: create a Map for O(1) lookup instead of O(n) iteration
593
+ let yMap = new Map();
594
+ for (let idx = 0; idx < yValues.length; idx++) {
595
+ let yv = yValues[idx];
596
+ yMap.set(yv, true);
597
+ }
598
+
594
599
  for (let idx = 0; idx < values.length; idx++) {
595
600
  let v = values[idx];
596
601
  let found = false;
597
- // testing by doing iteration is O(n2), could be slow
598
- // but Set::contains does not satisfy here
599
- let yValues = y.values();
600
- for (let idx = 0; idx < yValues.length; idx++) {
601
- let yv = yValues[idx];
602
- if (_$n__$e_(v, yv)) {
603
- found = true;
604
- break;
602
+ // First try direct lookup for primitive values
603
+ if (yMap.has(v)) {
604
+ found = true;
605
+ } else {
606
+ // Fallback to deep equality check for complex values
607
+ for (let yv of yValues) {
608
+ if (_$n__$e_(v, yv)) {
609
+ found = true;
610
+ break;
611
+ }
605
612
  }
606
613
  }
607
- if (found) {
608
- continue;
609
- } else {
614
+ if (!found) {
610
615
  return false;
611
616
  }
612
617
  }
@@ -696,14 +696,10 @@ export let round_$q_ = (a: number) => {
696
696
  return a === Math.round(a);
697
697
  };
698
698
  export let _$n_str_$o_concat = (a: string, b: string) => {
699
- let buffer = "";
700
- if (a != null) {
701
- buffer += toString(a, false);
702
- }
703
- if (b != null) {
704
- buffer += toString(b, false);
705
- }
706
- return buffer;
699
+ // Optimize string concatenation by avoiding unnecessary toString calls
700
+ const aStr = a != null ? toString(a, false) : "";
701
+ const bStr = b != null ? toString(b, false) : "";
702
+ return aStr + bStr;
707
703
  };
708
704
  export let sort = (xs: CalcitList | CalcitSliceList, f: CalcitFn): CalcitSliceList => {
709
705
  if (xs == null) {
@@ -907,7 +903,7 @@ export let parse_float = (x: string): number => {
907
903
  export let trim = (x: string, c: string): string => {
908
904
  if (c != null) {
909
905
  if (c.length !== 1) {
910
- throw new Error("Expceted c of a character");
906
+ throw new Error("Expected c of a character");
911
907
  }
912
908
  var buffer = x;
913
909
  var size = buffer.length;
@@ -270,7 +270,7 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
270
270
  throw new Error(`Expected pair of size 2, got: ${pair}`);
271
271
  }
272
272
  } else {
273
- throw new Error(`Expected pairs for reocrd, got: ${pair}`);
273
+ throw new Error(`Expected pairs for record, got: ${pair}`);
274
274
  }
275
275
  });
276
276
  entries.sort((a, b) => {
@@ -332,7 +332,7 @@ export let foldl = function (xs: CalcitValue, acc: CalcitValue, f: CalcitFn): Ca
332
332
  });
333
333
  return result;
334
334
  }
335
- throw new Error("Unknow data for foldl");
335
+ throw new Error("Unknown data for foldl");
336
336
  };
337
337
 
338
338
  export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: CalcitValue, f: CalcitFn): CalcitValue {
@@ -424,7 +424,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
424
424
  }
425
425
  return v0;
426
426
  }
427
- throw new Error("Unknow data for foldl-shortcut");
427
+ throw new Error("Unknown data for foldl-shortcut");
428
428
  };
429
429
  export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: CalcitValue, f: CalcitFn): CalcitValue {
430
430
  if (arguments.length !== 4) {
@@ -455,5 +455,5 @@ export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
455
455
  return v0;
456
456
  }
457
457
 
458
- throw new Error("Unknow data for foldr-shortcut, expected only list");
458
+ throw new Error("Unknown data for foldr-shortcut, expected only list");
459
459
  };
package/ts-src/js-map.mts CHANGED
@@ -176,7 +176,7 @@ export class CalcitMap {
176
176
  return new CalcitSet(ret);
177
177
  }
178
178
 
179
- /** detecthing in custom formatter */
179
+ /** detecting in custom formatter */
180
180
  nestedDataInChildren() {
181
181
  let pairs = this.pairs();
182
182
  for (let idx = 0; idx < pairs.length; idx++) {
@@ -392,7 +392,7 @@ export class CalcitSliceMap {
392
392
  return new CalcitSet(ret);
393
393
  }
394
394
 
395
- /** detecthing in custom formatter */
395
+ /** detecting in custom formatter */
396
396
  nestedDataInChildren() {
397
397
  let pairs = this.pairs();
398
398
  for (let idx = 0; idx < pairs.length; idx++) {
@@ -55,7 +55,7 @@ enum PseudoTypeIndex {
55
55
  }
56
56
 
57
57
  let typeAsInt = (x: CalcitValue): number => {
58
- // based on order used in Ord traint
58
+ // based on order used in Ord trait
59
59
  if (x == null) return PseudoTypeIndex.nil;
60
60
  let t = typeof x;
61
61
  if (t === "boolean") return PseudoTypeIndex.bool;
@@ -66,11 +66,13 @@ export class CalcitRecord {
66
66
  return idx >= 0;
67
67
  }
68
68
  toString(disableJsDataWarning: boolean = false): string {
69
- let ret = "(%{} " + this.name;
69
+ // Optimize string building using array join instead of concatenation
70
+ const parts = ["(%{} ", this.name.toString()];
70
71
  for (let idx = 0; idx < this.fields.length; idx++) {
71
- ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
72
+ parts.push(" (", this.fields[idx].toString(), " ", toString(this.values[idx], true, disableJsDataWarning), ")");
72
73
  }
73
- return ret + ")";
74
+ parts.push(")");
75
+ return parts.join("");
74
76
  }
75
77
  withClass(klass: CalcitValue): CalcitRecord {
76
78
  if (klass instanceof CalcitRecord) {