Skip to content
Open
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
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
sudo: false
language: node_js
node_js:
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
- "3"
- "2"
- "1"
- "0.12"
- "0.11"
- "0.10"
- "16"
- "14"
- "12"
before_script:
- npm install -g istanbul
script: istanbul cover -v test/run.js
after_success:
- npm install -g codeclimate-test-reporter
- codeclimate-test-reporter < coverage/lcov.info
env:
- CODECLIMATE_REPO_TOKEN=2ec835187f41b7f818cfa674baaf0048908beabca4d576692844b1d6739e3258
- CODECLIMATE_REPO_TOKEN=2ec835187f41b7f818cfa674baaf0048908beabca4d576692844b1d6739e3258
4 changes: 2 additions & 2 deletions bench/64K-pattern-memory-usage-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var log = console.log
, kb = 64
, msg = log( '- building and pre-processing a %dKB pattern..', kb )
, smem = process.memoryUsage()
, bp = new Buffer( 1024 * kb )
, bp = Buffer.alloc( 1024 * kb )
, emem0 = process.memoryUsage()
, bc = t.bcTable( bp )
, emem1 = process.memoryUsage()
Expand All @@ -23,4 +23,4 @@ var log = console.log

output( '[bc]', emem1, emem0, bc.length );
output( '[suff]', emem2, emem1, suff.length );
output( '[gs]', emem3, emem2, gs.length );
output( '[gs]', emem3, emem2, gs.length );
4 changes: 2 additions & 2 deletions bench/big-pattern-data-rate-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var log = console.log
, pmb = 20
, dlen = mb * 1024 * 1024
, plen = pmb * 1024 * 1024
, pattern = new Buffer( plen )
, data = new Buffer( dlen )
, pattern = Buffer.alloc( plen )
, data = Buffer.alloc( dlen )
, i = 0
, rand = 0
, bop = null
Expand Down
4 changes: 2 additions & 2 deletions bench/small-pattern-data-rate-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var log = console.log
Ipsum et Dolor sit amet, Quisquisce\r\n\r\n'
;

for ( var i = 0, c = 1, t = new Buffer( tSize ); i + len < tSize; i += len ){
for ( var i = 0, c = 1, t = Buffer.alloc( tSize ); i + len < tSize; i += len ){
if ( ( i % ( gap ) ) === 0 ) {
t.write( p.toString() + str, i );
indexes.push( i );
Expand Down Expand Up @@ -55,7 +55,7 @@ process.argv.forEach( function ( val, index, array ) {
( index === 4 ) ? ( pattern = ( ( val.length > 1 ) && ( val.length < 255 ) ) ? ( '--' + val + '\r\n' ) : pattern ) : null;
} );

var p = new Buffer( pattern )
var p = Buffer.alloc( pattern.length, pattern )
, msg = log( '- building test buffer' )
, t = buildTestBuffer( p, bsize, gapfactor )
, smem = process.memoryUsage()
Expand Down
2 changes: 1 addition & 1 deletion bench/small-pattern-memory-usage-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var log = console.log
, bytes = 255
, msg = log( '- building and pre-processing a short pattern.. (%d bytes)', bytes )
, smem = process.memoryUsage()
, bp = new Buffer( bytes )
, bp = Buffer.alloc( bytes )
, emem0 = process.memoryUsage()
, bc = t.bcTable( bp )
, emem1 = process.memoryUsage()
Expand Down
74 changes: 37 additions & 37 deletions example/bop-parse-example.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
/*
* Bop#parse and Bop#count example
*/
var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, CRLF = '\r\n'
, bop = Bop( CRLF )
, line = new Buffer( hello + CRLF )
, llen = line.length
, data = new Buffer( llen << 10 >>> 0 )
, i = 0
, l = 1024
, matches = null
, cnt = -1
;
log( '- pattern is:', bop.p );
log( '- fill data with %d lines:', l, line );
/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, i * llen );
matches = bop.parse( data );
log( '- matches:', matches.length );
cnt = bop.count( data, 0, false, true )
log( '- count:', cnt );
/*
* Bop#parse and Bop#count example
*/

var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, CRLF = '\r\n'
, bop = Bop( CRLF )
, line = Buffer.alloc(hello.length + CRLF.length, hello + CRLF)
, llen = line.length
, data = Buffer.alloc(llen << 10 >>> 0)
, i = 0
, l = 1024
, matches = null
, cnt = -1
;

log( '- pattern is:', bop.p );

log( '- fill data with %d lines:', l, line );

/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, i * llen );

matches = bop.parse( data );

log( '- matches:', matches.length );

cnt = bop.count( data, 0, false, true )

log( '- count:', cnt );

77 changes: 38 additions & 39 deletions example/bop-scount-example.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
/*
* Bop#sparse Bop#scount and Bop#count example
*/

var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, line = new Buffer( hello + hello )
, bop = Bop( line )
, llen = line.length
, l = 8
, data = new Buffer( 230 + llen * l )
, i = 0
, matches = null
, cnt = -1
;

log( '- pattern is:', bop.p );

log( '- fill data with %d patterns', l );

/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, 23 + i * llen );


matches = bop.sparse( data );

log( '\n-> use #sparse (no overlapping sequences).' );

log( '- bop.sparse(data) matches:', matches.length );

cnt = bop.scount( data, 0, true )

log( '- bop.scount(data, true):', cnt );

/*
* Bop#sparse Bop#scount and Bop#count example
*/

var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, line = Buffer.alloc(hello.length + hello.length, hello + hello)
, bop = Bop( line )
, llen = line.length
, l = 8
, data = Buffer.alloc(230 + llen * l)
, i = 0
, matches = null
, cnt = -1
;

log( '- pattern is:', bop.p );

log( '- fill data with %d patterns', l );

/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, 23 + i * llen );


matches = bop.sparse( data );

log( '\n-> use #sparse (no overlapping sequences).' );

log( '- bop.sparse(data) matches:', matches.length );

cnt = bop.scount( data, 0, true )

log( '- bop.scount(data, true):', cnt );
95 changes: 47 additions & 48 deletions example/bop-sparse-example.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
/*
* Bop#sparse Bop#parse and Bop#sparse example
*/

var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, line = new Buffer( hello + hello )
, bop = Bop( line )
, llen = line.length
, l = 8
, data = new Buffer( 23 + llen * l )
, i = 0
, matches = null
, cnt = -1
;

log( '- pattern is:', bop.p );

log( '- fill data with %d patterns', l );

/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, 23 + i * llen );

matches = bop.parse( data );

log( '\n-> use #parse (overlapping sequences).' );

log( '- bop.parse(data) matches:', matches.length );

cnt = bop.count( data )

log( '- bop.count(data):', cnt );

matches = bop.sparse( data );

log( '\n-> use #sparse (no overlapping sequences).' );

log( '- bop.sparse(data) matches:', matches.length );

cnt = bop.count( data, 0, true )

log( '- bop.count(data, true):', cnt );

/*
* Bop#sparse Bop#parse and Bop#sparse example
*/

var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, line = Buffer.alloc(hello.length + hello.length, hello + hello)
, bop = Bop( line )
, llen = line.length
, l = 8
, data = Buffer.alloc(23 + llen * l)
, i = 0
, matches = null
, cnt = -1
;

log( '- pattern is:', bop.p );

log( '- fill data with %d patterns', l );

/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, 23 + i * llen );

matches = bop.parse( data );

log( '\n-> use #parse (overlapping sequences).' );

log( '- bop.parse(data) matches:', matches.length );

cnt = bop.count( data )

log( '- bop.count(data):', cnt );

matches = bop.sparse( data );

log( '\n-> use #sparse (no overlapping sequences).' );

log( '- bop.sparse(data) matches:', matches.length );

cnt = bop.count( data, 0, true )

log( '- bop.count(data, true):', cnt );
10 changes: 5 additions & 5 deletions lib/bop.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.Bop = ( function () {
, suffixes = function ( p ) {
var m = p.length
, g = m - 1
, suff = ( m > 255 ) ? [] : new Buffer( m )
, suff = ( m > 255 ) ? [] : Buffer.alloc( m )
, f = 0
, i = 0
, offset = 0
Expand All @@ -42,7 +42,7 @@ exports.Bop = ( function () {
// good suffixes table
, gsTable = function ( suff ) {
var m = suff.length
, gsuff = ( m > 255 ) ? [] : new Buffer( m )
, gsuff = ( m > 255 ) ? [] : Buffer.alloc( m )
, i = m - 2
, j = 0
, offset = 0
Expand All @@ -60,7 +60,7 @@ exports.Bop = ( function () {
// bad char table
, bcTable = function ( p ) {
var m = p.length
, bc = ( m > 255 ) ? [] : new Buffer( 256 )
, bc = ( m > 255 ) ? [] : Buffer.alloc( 256 )
, i = 0
, blen = bc.length || m
;
Expand All @@ -72,7 +72,7 @@ exports.Bop = ( function () {
, convert = function ( data ) {
if ( ! isBuffer( data ) ) {
// obviously, string conversion is slow
if ( typeof data === 'string' ) return new Buffer( data );
if ( typeof data === 'string' ) return Buffer.alloc( data );
else throw new TypeError( 'the argument type should be Buffer or String' );
}
return data;
Expand Down Expand Up @@ -277,4 +277,4 @@ exports.Bop = ( function () {

return Bop;

} )();
} )();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
, "dependencies" : {}
, "main": "index"
, "engines" : {
"node" : ">=0.4.x"
"node" : ">=12"
}
, "scripts" : {
"test" : "bash test/run.sh"
Expand Down
4 changes: 2 additions & 2 deletions test/argument-type-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ assert.doesNotThrow(
log( '- passing a Buffer to constructor, doesn\'t throw an Error.' );
assert.doesNotThrow(
function() {
Bop( new Buffer( Date.now() + '' ) );
Bop( Buffer.alloc( Date.now() + '' ) );
},
'Test failed! An argument type different from String or Buffer, should throw an Error.'
);
Expand All @@ -25,4 +25,4 @@ assert.throws(
Bop( Date );
},
'Test failed! An argument type different from String or Buffer, should throw an Error.'
);
);
Loading