@waku/rln
Version:
RLN (Rate Limiting Nullifier) implementation for Waku
29 lines (26 loc) • 688 B
JavaScript
import { allocUnsafe } from '../../../../uint8arrays/dist/src/alloc.js';
/**
* A general purpose buffer pool
*/
function pool(size) {
const SIZE = 8192;
const MAX = SIZE >>> 1;
let slab;
let offset = SIZE;
return function poolAlloc(size) {
if (size < 1 || size > MAX) {
return allocUnsafe(size);
}
if (offset + size > SIZE) {
slab = allocUnsafe(SIZE);
offset = 0;
}
const buf = slab.subarray(offset, offset += size);
if ((offset & 7) !== 0) {
// align to 32 bit
offset = (offset | 7) + 1;
}
return buf;
};
}
export { pool as default };