Skip to content

Commit

Permalink
use needleLastCharIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Dec 2, 2024
1 parent af2c289 commit daf712e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions deps/streamsearch/sbmh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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)
Expand Down

0 comments on commit daf712e

Please sign in to comment.