Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rewriting the count_lines function #67

Closed
wants to merge 2 commits into from

3 participants

@UncleBill

Faster and easier to read and understand, and higher performance.

UncleBill added some commits
@UncleBill UncleBill Rewrite the count_lines for performance
Faster and easier to read and understand.
712b1b4
@UncleBill UncleBill Improve the count_lines fucntion
don't consider empty lines.
d1e8f07
@ashb
Collaborator

Sorry we missed this pull request when you first opened it.

Do you have the benchmarking code you used to test this? I can believe it would be faster but I'm curious to see by how much (and what difference it makes in various engines.)

Also /\n+/ should be /\n/ otherwise you don't count double empty lines correctly - but it looks like there aren't any tests for this yet. Our bad.

@evilstreak evilstreak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2012
  1. @UncleBill

    Rewrite the count_lines for performance

    UncleBill authored
    Faster and easier to read and understand.
Commits on Nov 28, 2012
  1. @UncleBill

    Improve the count_lines fucntion

    UncleBill authored
    don't consider empty lines.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 3 deletions.
  1. +1 −3 lib/markdown.js
View
4 lib/markdown.js
@@ -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.trim().split( /\n+/ ).length;
}
// Internal - split source into rough blocks
Something went wrong with that request. Please try again.