From daf712ef65300f089008a4eb9a2d7c0fa77ce50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Mon, 2 Dec 2024 15:21:13 +0100 Subject: [PATCH] use needleLastCharIndex --- deps/streamsearch/sbmh.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deps/streamsearch/sbmh.js b/deps/streamsearch/sbmh.js index b2b760e..79d3150 100644 --- a/deps/streamsearch/sbmh.js +++ b/deps/streamsearch/sbmh.js @@ -40,6 +40,7 @@ function SBMH (needle) { } const needleLength = needle.length + const needleLastCharIndex = needleLength - 1 if (needleLength === 0) { throw new Error('The needle cannot be an empty String/Buffer.') @@ -58,12 +59,12 @@ function SBMH (needle) { this._needle = needle this._bufpos = 0 - this._lookbehind = Buffer.alloc(needleLength - 1) + this._lookbehind = Buffer.alloc(needleLastCharIndex) // Populate occurrence table with analysis of the needle, // ignoring last letter. - for (var i = 0; i < needleLength - 1; ++i) { // eslint-disable-line no-var - this._occ[needle[i]] = needleLength - 1 - i + for (var i = 0; i < needleLastCharIndex; ++i) { // eslint-disable-line no-var + this._occ[needle[i]] = needleLastCharIndex - i } } inherits(SBMH, EventEmitter)