Skip to content

Commit

Permalink
perf(utils): fast prepareValue (#3370)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cesco69 authored Feb 10, 2025
1 parent f10f569 commit 751e741
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions packages/pg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,28 @@ var prepareValue = function (val, seen) {
if (val == null) {
return null
}
if (val instanceof Buffer) {
return val
}
if (ArrayBuffer.isView(val)) {
var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)
if (buf.length === val.byteLength) {
return buf
if (typeof val === 'object') {
if (val instanceof Buffer) {
return val
}
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
}
if (val instanceof Date) {
if (defaults.parseInputDatesAsUTC) {
return dateToStringUTC(val)
} else {
return dateToString(val)
if (ArrayBuffer.isView(val)) {
var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)
if (buf.length === val.byteLength) {
return buf
}
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
}
}
if (Array.isArray(val)) {
return arrayString(val)
}
if (typeof val === 'object') {
if (val instanceof Date) {
if (defaults.parseInputDatesAsUTC) {
return dateToStringUTC(val)
} else {
return dateToString(val)
}
}
if (Array.isArray(val)) {
return arrayString(val)
}

return prepareObject(val, seen)
}
return val.toString()
Expand Down

0 comments on commit 751e741

Please sign in to comment.