writer: alloc pool lazily.
This commit is contained in:
parent
a543648310
commit
45e41b1bb4
@ -10,8 +10,10 @@ const assert = require('assert');
|
||||
const encoding = require('./encoding');
|
||||
const digest = require('../crypto/digest');
|
||||
|
||||
const POOL = Buffer.allocUnsafeSlow(100 * 1024);
|
||||
const EMPTY = Buffer.alloc(0);
|
||||
const POOLSIZE = 100 << 10;
|
||||
|
||||
let POOL = null;
|
||||
|
||||
/**
|
||||
* Statically allocated buffer writer.
|
||||
@ -35,11 +37,15 @@ function StaticWriter(size) {
|
||||
*/
|
||||
|
||||
StaticWriter.pool = function pool(size) {
|
||||
if (size <= POOL.length) {
|
||||
if (size <= POOLSIZE) {
|
||||
if (!POOL)
|
||||
POOL = Buffer.allocUnsafeSlow(POOLSIZE);
|
||||
|
||||
const bw = new StaticWriter(0);
|
||||
bw.data = POOL.slice(0, size);
|
||||
return bw;
|
||||
}
|
||||
|
||||
return new StaticWriter(size);
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user