Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix review comments
  • Loading branch information
thefourtheye committed Aug 11, 2016
commit 2ee392b0ee4e104d661924b09de48aae3c9dee04
16 changes: 6 additions & 10 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,19 @@ function convertProtocols(protocols) {
exports.convertNPNProtocols = function(protocols, out) {
// If protocols is Array - translate it into buffer
if (Array.isArray(protocols)) {
protocols = convertProtocols(protocols);
}
// If it's already a Buffer - store it
if (protocols instanceof Buffer) {
// copy new buffer not to be modified by user
out.NPNProtocols = convertProtocols(protocols);
} else if (protocols instanceof Buffer) {
// Copy new buffer not to be modified by user.
out.NPNProtocols = Buffer.from(protocols);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inefficient (in a minor way) if protocols was originally an array. In that case two buffers are created, here and in convertProtocols().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
};

exports.convertALPNProtocols = function(protocols, out) {
// If protocols is Array - translate it into buffer
if (Array.isArray(protocols)) {
protocols = convertProtocols(protocols);
}
// If it's already a Buffer - store it
if (protocols instanceof Buffer) {
// copy new buffer not to be modified by user
out.ALPNProtocols = convertProtocols(protocols);
} else if (protocols instanceof Buffer) {
// Copy new buffer not to be modified by user.
out.ALPNProtocols = Buffer.from(protocols);
}
};
Expand Down