mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
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
This commit is contained in:
parent
f10f569a8a
commit
751e7410d9
@ -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
|
||||
}
|
||||
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 (Array.isArray(val)) {
|
||||
return arrayString(val)
|
||||
}
|
||||
if (typeof val === 'object') {
|
||||
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
|
||||
}
|
||||
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 (Array.isArray(val)) {
|
||||
return arrayString(val)
|
||||
}
|
||||
|
||||
return prepareObject(val, seen)
|
||||
}
|
||||
return val.toString()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user