Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
branches:
- master
- v5.x
paths-ignore:
- '**.md'
jobs:
Expand Down
7 changes: 3 additions & 4 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/

var utils = require('./utils'),
buffer = require('buffer'), // For `SlowBuffer`.
buffer = require('buffer'),
util = require('util');

var Buffer = buffer.Buffer;
var SlowBuffer = buffer.SlowBuffer;

// Convenience imports.
var Tap = utils.Tap;
Expand Down Expand Up @@ -48,7 +47,7 @@ var TYPES = {
var RANDOM = new utils.Lcg();

// Encoding tap (shared for performance).
var TAP = new Tap(new SlowBuffer(1024));
var TAP = new Tap(utils.newSlowBuffer(1024));

// Currently active logical type, used for name redirection.
var LOGICAL_TYPE = null;
Expand Down Expand Up @@ -453,7 +452,7 @@ Type.isType = function (/* any, [prefix] ... */) {

Type.__reset = function (size) {
debug('resetting type buffer to %d', size);
TAP.buf = new SlowBuffer(size);
TAP.buf = utils.newSlowBuffer(size);
};

Object.defineProperty(Type.prototype, 'branchName', {
Expand Down
11 changes: 10 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var buffer = require('buffer');
var crypto = require('crypto');
var util = require('util');

var Buffer = buffer.Buffer;
var Buffer = buffer.Buffer;

// Shared buffer pool for all taps.
var POOL = new BufferPool(4096);
Expand All @@ -35,6 +35,14 @@ function newBuffer(size) {
}
}

function newSlowBuffer(size) {
if (typeof Buffer.allocUnsafeSlow == 'function') {
return Buffer.allocUnsafeSlow(size);
} else {
return new buffer.SlowBuffer(size);
}
}

/**
* Create a new buffer with the input contents.
*
Expand Down Expand Up @@ -952,6 +960,7 @@ module.exports = {
isValidName: isValidName,
jsonEnd: jsonEnd,
newBuffer: newBuffer,
newSlowBuffer: newSlowBuffer,
objectValues: objectValues,
qualify: qualify,
toMap: toMap,
Expand Down