Skip to content

Commit 088ab2f

Browse files
committed
Use subarray instead of slice
1 parent 0555a7a commit 088ab2f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/bytes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ const b = Object.assign(reset, messages, {
4747
return b
4848
},
4949
raw(x) {
50-
buffer = Buffer.concat([buffer.slice(0, b.i), x])
50+
buffer = Buffer.concat([buffer.subarray(0, b.i), x])
5151
b.i = buffer.length
5252
return b
5353
},
5454
end(at = 1) {
5555
buffer.writeUInt32BE(b.i - at, at)
56-
const out = buffer.slice(0, b.i)
56+
const out = buffer.subarray(0, b.i)
5757
b.i = 0
5858
buffer = Buffer.allocUnsafe(size)
5959
return out

src/connection.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
309309
}
310310

311311
try {
312-
handle(incoming.slice(0, length + 1))
312+
handle(incoming.subarray(0, length + 1))
313313
} catch (e) {
314314
query && (query.cursorFn || query.describeFirst) && write(Sync)
315315
errored(e)
316316
}
317-
incoming = incoming.slice(length + 1)
317+
incoming = incoming.subarray(length + 1)
318318
remaining = 0
319319
incomings = null
320320
}
@@ -483,7 +483,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
483483
value = length === -1
484484
? null
485485
: query.isRaw === true
486-
? x.slice(index, index += length)
486+
? x.subarray(index, index += length)
487487
: column.parser === undefined
488488
? x.toString('utf8', index, index += length)
489489
: column.parser.array === true
@@ -652,7 +652,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
652652

653653
async function AuthenticationMD5Password(x) {
654654
write(
655-
b().p().str('md5' + md5(Buffer.concat([Buffer.from(md5((await Pass()) + user)), x.slice(9)]))).z(1).end()
655+
b().p().str('md5' + md5(Buffer.concat([Buffer.from(md5((await Pass()) + user)), x.subarray(9)]))).z(1).end()
656656
)
657657
}
658658

@@ -851,7 +851,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
851851
}
852852

853853
function CopyData(x) {
854-
stream.push(x.slice(5)) || socket.pause()
854+
stream.push(x.subarray(5)) || socket.pause()
855855
}
856856

857857
function CopyDone() {

src/subscribe.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default function Subscribe(postgres, options) {
103103

104104
function data(x) {
105105
if (x[0] === 0x77)
106-
parse(x.slice(25), state, sql.options.parsers, handle)
106+
parse(x.subarray(25), state, sql.options.parsers, handle)
107107
else if (x[0] === 0x6b && x[17])
108108
pong()
109109
}
@@ -143,8 +143,8 @@ function parse(x, state, parsers, handle) {
143143
R: x => { // Relation
144144
let i = 1
145145
const r = state[x.readUInt32BE(i)] = {
146-
schema: String(x.slice(i += 4, i = x.indexOf(0, i))) || 'pg_catalog',
147-
table: String(x.slice(i + 1, i = x.indexOf(0, i + 1))),
146+
schema: String(x.subarray(i += 4, i = x.indexOf(0, i))) || 'pg_catalog',
147+
table: String(x.subarray(i + 1, i = x.indexOf(0, i + 1))),
148148
columns: Array(x.readUInt16BE(i += 2)),
149149
keys: []
150150
}
@@ -156,7 +156,7 @@ function parse(x, state, parsers, handle) {
156156
while (i < x.length) {
157157
column = r.columns[columnIndex++] = {
158158
key: x[i++],
159-
name: String(x.slice(i, i = x.indexOf(0, i))),
159+
name: String(x.subarray(i, i = x.indexOf(0, i))),
160160
type: x.readUInt32BE(i += 1),
161161
parser: parsers[x.readUInt32BE(i)],
162162
atttypmod: x.readUInt32BE(i += 4)
@@ -170,7 +170,7 @@ function parse(x, state, parsers, handle) {
170170
O: () => { /* noop */ }, // Origin
171171
B: x => { // Begin
172172
state.date = Time(x.readBigInt64BE(9))
173-
state.lsn = x.slice(1, 9)
173+
state.lsn = x.subarray(1, 9)
174174
},
175175
I: x => { // Insert
176176
let i = 1

0 commit comments

Comments
 (0)