Skip to content

Commit

Permalink
Revert "simplify match function"
Browse files Browse the repository at this point in the history
This reverts commit cc5b1da which was causing problems in some downstream modules, not caught by the test suite — I will try to follow with a test case and figure out what's the problem.
  • Loading branch information
mourner committed Mar 16, 2016
1 parent 5b3d834 commit 8eac05e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ function BinarySplit (matcher) {

function firstMatch (buf, offset) {
if (offset >= buf.length) return -1

for (var i = offset, m = matcher.length; i < buf.length - m; i++) {
for (var j = 0; j < m; j++) {
if (buf[i + j] !== matcher[j]) break
for (var i = offset; i < buf.length; i++) {
if (buf[i] === matcher[0]) {
if (matcher.length > 1) {
var fullMatch = true
for (var j = i, k = 0; j < i + matcher.length; j++, k++) {
if (buf[j] !== matcher[k]) {
fullMatch = false
break
}
}
if (fullMatch) return j - matcher.length
} else {
break
}
}
if (j === m) return i
}
return buf.length

var idx = i + matcher.length - 1
return idx
}
}

0 comments on commit 8eac05e

Please sign in to comment.