Skip to content

Commit 751e741

Browse files
authored
perf(utils): fast prepareValue (#3370)
* perf(utils): fast prepareValue This PR add a performance improvements at prepare Value for non-object by skipping useless condition * fix: lint * fix: case of undefined * fix: review
1 parent f10f569 commit 751e741

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

packages/pg/lib/utils.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,28 @@ var prepareValue = function (val, seen) {
4949
if (val == null) {
5050
return null
5151
}
52-
if (val instanceof Buffer) {
53-
return val
54-
}
55-
if (ArrayBuffer.isView(val)) {
56-
var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)
57-
if (buf.length === val.byteLength) {
58-
return buf
52+
if (typeof val === 'object') {
53+
if (val instanceof Buffer) {
54+
return val
5955
}
60-
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
61-
}
62-
if (val instanceof Date) {
63-
if (defaults.parseInputDatesAsUTC) {
64-
return dateToStringUTC(val)
65-
} else {
66-
return dateToString(val)
56+
if (ArrayBuffer.isView(val)) {
57+
var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)
58+
if (buf.length === val.byteLength) {
59+
return buf
60+
}
61+
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
6762
}
68-
}
69-
if (Array.isArray(val)) {
70-
return arrayString(val)
71-
}
72-
if (typeof val === 'object') {
63+
if (val instanceof Date) {
64+
if (defaults.parseInputDatesAsUTC) {
65+
return dateToStringUTC(val)
66+
} else {
67+
return dateToString(val)
68+
}
69+
}
70+
if (Array.isArray(val)) {
71+
return arrayString(val)
72+
}
73+
7374
return prepareObject(val, seen)
7475
}
7576
return val.toString()

0 commit comments

Comments
 (0)