Permalink
Browse files

Rewrite the count_lines for performance

Faster and easier to read and understand.
  • Loading branch information...
1 parent 50f6d69 commit 712b1b41eaf1f931ec3c8c42f585d3258d9f610a @UncleBill committed Nov 27, 2012
Showing with 1 addition and 3 deletions.
  1. +1 −3 lib/markdown.js
View
@@ -153,9 +153,7 @@ var mk_block = Markdown.mk_block = function(block, trail, line) {
};
function count_lines( str ) {
- var n = 0, i = -1;
- while ( ( i = str.indexOf('\n', i+1) ) !== -1) n++;
- return n;
+ return str.split( '\n' ).length + 1;
}
// Internal - split source into rough blocks

0 comments on commit 712b1b4

Please sign in to comment.