@stoolap/node 0.5.0-beta.3 → 0.5.0-beta.4

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.
Files changed (2) hide show
  1. package/lib/parse.js +33 -1
  2. package/package.json +6 -6
package/lib/parse.js CHANGED
@@ -13,6 +13,35 @@ const td = new TextDecoder();
13
13
 
14
14
  let _off = 0;
15
15
 
16
+ /* Short ASCII strings are cut from a latin1 decode of an 8 KB block of the
17
+ * buffer instead of one Buffer.toString call per value: latin1 maps bytes to
18
+ * chars one to one, so offsets hold, and String.prototype.substring is a pure
19
+ * V8 operation (~10 ns against ~40 ns for toString). Measured crossover is
20
+ * about 40 bytes; longer values and any value with a byte >= 0x80 take the
21
+ * utf8 path. The block is bounded so a kept string pins at most 8 KB. */
22
+ const ASCII_FAST_MAX = 32;
23
+ const BLOCK_SIZE = 8192;
24
+ let _blk = "";
25
+ let _blkStart = -1;
26
+ let _blkEnd = -1;
27
+
28
+ function readText(bytes, nb, start, len) {
29
+ const end = start + len;
30
+ if (len <= ASCII_FAST_MAX) {
31
+ let k = start;
32
+ while (k < end && bytes[k] < 128) k++;
33
+ if (k === end) {
34
+ if (start < _blkStart || end > _blkEnd) {
35
+ _blkStart = start;
36
+ _blkEnd = Math.max(end, Math.min(bytes.length, start + BLOCK_SIZE));
37
+ _blk = nb.toString("latin1", _blkStart, _blkEnd);
38
+ }
39
+ return _blk.substring(start - _blkStart, end - _blkStart);
40
+ }
41
+ }
42
+ return nb.toString("utf8", start, end);
43
+ }
44
+
16
45
  function readVal(bytes, dv, nb) {
17
46
  const tag = bytes[_off++];
18
47
  switch (tag) {
@@ -39,7 +68,7 @@ function readVal(bytes, dv, nb) {
39
68
  const start = _off;
40
69
  _off += len;
41
70
  return nb
42
- ? nb.toString("utf8", start, start + len)
71
+ ? readText(bytes, nb, start, len)
43
72
  : td.decode(
44
73
  new Uint8Array(bytes.buffer, bytes.byteOffset + start, len),
45
74
  );
@@ -75,6 +104,7 @@ function parseRows(abuf) {
75
104
  const nb = _hasBuffer ? Buffer.from(abuf) : null;
76
105
 
77
106
  _off = 0;
107
+ _blkEnd = -1;
78
108
  const colCount = dv.getUint32(0, true);
79
109
  _off = 4;
80
110
  const colNames = new Array(colCount);
@@ -107,6 +137,7 @@ function parseRaw(abuf) {
107
137
  const nb = _hasBuffer ? Buffer.from(abuf) : null;
108
138
 
109
139
  _off = 0;
140
+ _blkEnd = -1;
110
141
  const colCount = dv.getUint32(0, true);
111
142
  _off = 4;
112
143
  const colNames = new Array(colCount);
@@ -176,6 +207,7 @@ function parseRowsCached(abuf, headerOff, factory, colCount) {
176
207
  const dv = new DataView(abuf);
177
208
  const nb = _hasBuffer ? Buffer.from(abuf) : null;
178
209
  _off = headerOff;
210
+ _blkEnd = -1;
179
211
  const rowCount = dv.getUint32(_off, true);
180
212
  _off += 4;
181
213
  const results = new Array(rowCount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoolap/node",
3
- "version": "0.5.0-beta.3",
3
+ "version": "0.5.0-beta.4",
4
4
  "description": "High-performance Node.js driver for Stoolap embedded SQL database",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,11 +18,11 @@
18
18
  "bench": "node benchmark.mjs"
19
19
  },
20
20
  "optionalDependencies": {
21
- "@stoolap/lib-darwin-arm64": "0.5.0-beta.3",
22
- "@stoolap/lib-darwin-x64": "0.5.0-beta.3",
23
- "@stoolap/lib-linux-arm64-gnu": "0.5.0-beta.3",
24
- "@stoolap/lib-linux-x64-gnu": "0.5.0-beta.3",
25
- "@stoolap/lib-win32-x64-msvc": "0.5.0-beta.3"
21
+ "@stoolap/lib-darwin-arm64": "0.5.0-beta.4",
22
+ "@stoolap/lib-darwin-x64": "0.5.0-beta.4",
23
+ "@stoolap/lib-linux-arm64-gnu": "0.5.0-beta.4",
24
+ "@stoolap/lib-linux-x64-gnu": "0.5.0-beta.4",
25
+ "@stoolap/lib-win32-x64-msvc": "0.5.0-beta.4"
26
26
  },
27
27
  "devDependencies": {
28
28
  "better-sqlite3": "^12.6.2",