padolsey/relevancy.js

Efficiency in _generateSubjectRegex

Opened this issue · 0 comments

I don't know if this is actively maintained.

I looked into the code and see _generateSubjectRegex required a sort(), while we can traverse in another order to avoid the sort.

for (let currLength = subject.length; currLength > 0; currLength--) {
  for (
    let startIndex = 0;
    startIndex + currLength <= subject.length;
    startIndex++
  ) {
    let sequence = subject.substr(startIndex, currLength);

Also, it generates duplicated substrings. I haven't checked its impact on Regex.