Skip to content

Commit 355523f

Browse files
committed
buffer: refactor module.exports, imports
* Move to more efficient module.exports pattern * Refactor requires * Eliminate circular dependency on internal/buffer * Add names to some functions * Fix circular dependency error in assert.js PR-URL: #13807 Reviewed-By: Refael Ackermann <[email protected]>
1 parent 45b730e commit 355523f

File tree

3 files changed

+327
-295
lines changed

3 files changed

+327
-295
lines changed

lib/assert.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const { compare } = process.binding('buffer');
2424
const util = require('util');
2525
const { isSet, isMap } = process.binding('util');
2626
const { objectToString } = require('internal/util');
27-
const { Buffer } = require('buffer');
2827
const errors = require('internal/errors');
2928

3029
// The assert module provides functions that throw
@@ -119,6 +118,7 @@ function areSimilarRegExps(a, b) {
119118
// barrier including the Buffer.from operation takes the advantage of the faster
120119
// compare otherwise. 300 was the number after which compare became faster.
121120
function areSimilarTypedArrays(a, b) {
121+
const { from } = require('buffer').Buffer;
122122
const len = a.byteLength;
123123
if (len !== b.byteLength) {
124124
return false;
@@ -131,12 +131,8 @@ function areSimilarTypedArrays(a, b) {
131131
}
132132
return true;
133133
}
134-
return compare(Buffer.from(a.buffer,
135-
a.byteOffset,
136-
len),
137-
Buffer.from(b.buffer,
138-
b.byteOffset,
139-
b.byteLength)) === 0;
134+
return compare(from(a.buffer, a.byteOffset, len),
135+
from(b.buffer, b.byteOffset, b.byteLength)) === 0;
140136
}
141137

142138
function isFloatTypedArrayTag(tag) {

0 commit comments

Comments
 (0)