Skip to content

Commit

Permalink
buffer: refactor module.exports, imports
Browse files Browse the repository at this point in the history
* 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 <refack@gmail.com>
  • Loading branch information
jasnell committed Jul 24, 2017
1 parent 45b730e commit 355523f
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 295 deletions.
10 changes: 3 additions & 7 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const { compare } = process.binding('buffer');
const util = require('util');
const { isSet, isMap } = process.binding('util');
const { objectToString } = require('internal/util');
const { Buffer } = require('buffer');
const errors = require('internal/errors');

// The assert module provides functions that throw
Expand Down Expand Up @@ -119,6 +118,7 @@ function areSimilarRegExps(a, b) {
// barrier including the Buffer.from operation takes the advantage of the faster
// compare otherwise. 300 was the number after which compare became faster.
function areSimilarTypedArrays(a, b) {
const { from } = require('buffer').Buffer;
const len = a.byteLength;
if (len !== b.byteLength) {
return false;
Expand All @@ -131,12 +131,8 @@ function areSimilarTypedArrays(a, b) {
}
return true;
}
return compare(Buffer.from(a.buffer,
a.byteOffset,
len),
Buffer.from(b.buffer,
b.byteOffset,
b.byteLength)) === 0;
return compare(from(a.buffer, a.byteOffset, len),
from(b.buffer, b.byteOffset, b.byteLength)) === 0;
}

function isFloatTypedArrayTag(tag) {
Expand Down
Loading

0 comments on commit 355523f

Please sign in to comment.