Skip to content

Commit f158693

Browse files
authored
perf(pg-native): pre-shaped result rows (#3369)
* perf(pg-native): pre-shaped result rows Porting on pg-native #3042 * fix: lint * perf(pg-native): avoid useless spread
1 parent 0792f09 commit f158693

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/pg-native/lib/build-result.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Result {
99
this.rowCount = undefined
1010
this.fields = []
1111
this.rows = []
12+
this._prebuiltEmptyResultObject = null
1213
}
1314

1415
consumeCommand(pq) {
@@ -19,9 +20,12 @@ class Result {
1920
consumeFields(pq) {
2021
const nfields = pq.nfields()
2122
this.fields = new Array(nfields)
23+
this._prebuiltEmptyResultObject = {}
2224
for (var x = 0; x < nfields; x++) {
25+
var name = pq.fname(x)
26+
this._prebuiltEmptyResultObject[name] = null
2327
this.fields[x] = {
24-
name: pq.fname(x),
28+
name: name,
2529
dataTypeID: pq.ftype(x),
2630
}
2731
}
@@ -36,7 +40,7 @@ class Result {
3640
}
3741

3842
consumeRowAsObject(pq, rowIndex) {
39-
const row = {}
43+
const row = { ...this._prebuiltEmptyResultObject }
4044
for (var j = 0; j < this.fields.length; j++) {
4145
row[this.fields[j].name] = this.readValue(pq, rowIndex, j)
4246
}

0 commit comments

Comments
 (0)