Skip to content

Commit

Permalink
Use Buffer.allocUnsafe to reduce allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
chkimes authored Jul 13, 2022
1 parent fd93de3 commit 2f952fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ C.sendMessage = function(channel,
var allLen = methodHeaderLen + bodyLen;

if (allLen < SINGLE_CHUNK_THRESHOLD) {
var all = Buffer.alloc(allLen);
var all = Buffer.allocUnsafe(allLen);
var offset = mframe.copy(all, 0);
offset += pframe.copy(all, offset);

Expand All @@ -570,7 +570,7 @@ C.sendMessage = function(channel,
}
else {
if (methodHeaderLen < SINGLE_CHUNK_THRESHOLD) {
var both = Buffer.alloc(methodHeaderLen);
var both = Buffer.allocUnsafe(methodHeaderLen);
var offset = mframe.copy(both, 0);
pframe.copy(both, offset);
buffer.write(both);
Expand Down

0 comments on commit 2f952fe

Please sign in to comment.