From cffae659b83975ff9b2233fd64d5a55214c5f1b9 Mon Sep 17 00:00:00 2001 From: jeromew Date: Wed, 20 Mar 2019 09:21:28 +0000 Subject: [PATCH] perf: remove one call to push in copy-from transform loop --- README.md | 2 ++ index.js | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 05558d4..89e3550 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Since this isn't a module with tons of installs and dependent modules I hope we ### version 2.x - published YYYY-MM-DD + * Small refactor in copy-from passing from 3 push to 2 push in every chunk transform loop + ### version 2.1.0 - published 2019-03-19 * Change README to stop using the pg pool singleton (removed after pg 7.0) diff --git a/index.js b/index.js index a170c72..0292ef5 100644 --- a/index.js +++ b/index.js @@ -30,12 +30,10 @@ CopyStreamQuery.prototype.submit = function(connection) { } -var copyDataBuffer = Buffer.from([code.CopyData]) CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { var Int32Len = 4; - this.push(copyDataBuffer) - var lenBuffer = Buffer.alloc(Int32Len) - lenBuffer.writeUInt32BE(chunk.length + Int32Len, 0) + var lenBuffer = Buffer.from([code.CopyData, 0, 0, 0, 0]) + lenBuffer.writeUInt32BE(chunk.length + Int32Len, 1) this.push(lenBuffer) this.push(chunk) cb()