Skip to content

Commit d3f8149

Browse files
committed
make it fast again for input with many short lines
see #8 (comment)
1 parent ee24ff0 commit d3f8149

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ function BinarySplit (matcher) {
99
matcher = bops.from(matcher || os.EOL)
1010
var buffered
1111
var bufcount = 0
12-
var offset = 0
1312
return through(write, end)
1413

1514
function write (buf, enc, done) {
1615
bufcount++
17-
16+
var offset = 0
17+
var lastMatch = 0
1818
if (buffered) {
1919
buf = bops.join([buffered, buf])
20+
offset = buffered.length
2021
buffered = undefined
2122
}
2223

23-
while (buf) {
24+
while (true) {
2425
var idx = firstMatch(buf, offset)
2526
if (idx !== -1 && idx < buf.length) {
26-
this.push(bops.subarray(buf, 0, idx))
27-
buf = bops.subarray(buf, idx + matcher.length)
28-
offset = 0
27+
this.push(bops.subarray(buf, lastMatch, idx))
28+
offset = idx + matcher.length
29+
lastMatch = offset
2930
} else {
30-
buffered = buf
31-
offset = buf.length
32-
buf = undefined
31+
buffered = bops.subarray(buf, lastMatch)
32+
break
3333
}
3434
}
3535

0 commit comments

Comments
 (0)