Skip to content

Commit 426d42e

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
1 parent aa1c8c0 commit 426d42e

File tree

3 files changed

+327
-295
lines changed

3 files changed

+327
-295
lines changed

lib/assert.js

Lines changed: 3 additions & 7 deletions
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
@@ -124,6 +123,7 @@ function areSimilarRegExps(a, b) {
124123
// The c++ barrier takes the advantage of the faster compare otherwise.
125124
// 300 was the number after which compare became faster.
126125
function areSimilarTypedArrays(a, b) {
126+
const { from } = require('buffer').Buffer;
127127
const len = a.byteLength;
128128
if (len !== b.byteLength) {
129129
return false;
@@ -136,12 +136,8 @@ function areSimilarTypedArrays(a, b) {
136136
}
137137
return true;
138138
}
139-
return compare(Buffer.from(a.buffer,
140-
a.byteOffset,
141-
len),
142-
Buffer.from(b.buffer,
143-
b.byteOffset,
144-
b.byteLength)) === 0;
139+
return compare(from(a.buffer, a.byteOffset, len),
140+
from(b.buffer, b.byteOffset, b.byteLength)) === 0;
145141
}
146142

147143
function isFloatTypedArrayTag(tag) {

0 commit comments

Comments
 (0)