Skip to content

Commit

Permalink
chore: make table an arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Sep 27, 2024
1 parent ef1ef17 commit a9debd1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bench
await bench.warmup();
await bench.run();

console.table(bench.table());
console.warn("gmatch matches:", gmatchMatches);
console.warn("streamsearch matches:", streamsearchMatches);
globalThis.console.table(bench.table());
globalThis.console.warn("gmatch matches:", gmatchMatches);
globalThis.console.warn("streamsearch matches:", streamsearchMatches);
})();
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import grules from "grules";

export default [...grules];
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"c8": "^10.1.2",
"grules": "^0.23.0",
"grules": "^0.24.2",
"streamsearch": "^1.1.0",
"tinybench": "^2.8.0",
"typescript": ">=5.5.4"
"tinybench": "^2.9.0",
"typescript": ">=5.6.2"
},
"repository": {
"type": "git",
Expand Down
16 changes: 7 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bufferTextEncoder = new TextEncoder();
const bufferTextEncoder = new globalThis.TextEncoder();

const bufferFrom = (string) => {
return bufferTextEncoder.encode(string);
Expand All @@ -24,10 +24,9 @@ export const Match = class {
#matches;

/**
* The `Match` class implements a streaming Boyer-Moore-Horspool-Sunday (BMHS) pattern matching algorithm.
* @param {string} pattern The pattern to search for.
* @param {Function} callback The function to be called when there's a match or when a chunk of data is processed.
* @param {Function} from The native or custom `Buffer.from` implementation for runtimes like Node.js.
* @param {string} pattern pattern
* @param {Function} callback callback
* @param {Function} from from
* @throws {TypeError}
* @throws {RangeError}
*/
Expand Down Expand Up @@ -79,8 +78,7 @@ export const Match = class {
}

/**
* Feeds a chunk of data.
* @param {Uint8Array|ArrayBuffer|string} chunk The data to be fed.
* @param {Uint8Array|ArrayBuffer|string} chunk chunk
*/
write(chunk) {
const buffer =
Expand Down Expand Up @@ -204,13 +202,13 @@ export const Match = class {
return true;
}

static #table(pattern) {
static #table = (pattern) => {
const table = new Uint8Array(256).fill(pattern.length);

for (let i = 0, length = pattern.length - 1; i !== length; ++i) {
table[pattern[i]] = length - i;
}

return table;
}
};
};

0 comments on commit a9debd1

Please sign in to comment.