Replace `count_lines` with faster implementation

This patch replaces `count_lines` with a faster implementation.

```
current method:

console.time('count_lines'); for (i=0; i<100000; i++) { count_lines(longString) }; console.timeEnd('count_lines')
count_lines: 221.655ms

new version:

console.time('count_lines'); for (i=0; i<100000; i++) { count_lines(longString) }; console.timeEnd('count_lines')
count_lines: 114.764ms
```