-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(perf): optimize hit counting and source map performance
Fixes #159
- Loading branch information
Showing
9 changed files
with
126 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.{.js,.json}] | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
test/fixtures/scripts/needs-compile.js eol=crlf | ||
test/fixtures/scripts/needs-compile.compiled.js eol=crlf | ||
test/fixtures/scripts/needs-compile.compiled.js.map eol=crlf | ||
test/fixtures/scripts/needs-compile.compiled.js.map eol=crlf | ||
test/fixtures/scripts/branches.covered.js eol=lf | ||
test/fixtures/scripts/branches.js eol=lf | ||
test/fixtures/scripts/functions.js eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ coverage | |
node_modules | ||
.idea | ||
.vscode | ||
*.iml | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* ...something resembling a binary search, to find the lowest line within the range. | ||
* And then you could break as soon as the line is longer than the range... | ||
*/ | ||
module.exports.sliceRange = (lines, startCol, endCol, inclusive = false) => { | ||
let start = 0 | ||
let end = lines.length - 1 | ||
|
||
/** | ||
* I consider this a temporary solution until I find an alternaive way to fix the "off by one issue" | ||
*/ | ||
const extStartCol = inclusive ? startCol - 1 : startCol | ||
|
||
while (start < end) { | ||
const mid = (start + end) >> 1 | ||
if (lines[mid].startCol <= startCol && lines[mid].endCol > extStartCol) { | ||
start = mid | ||
end = start | ||
} else if (lines[mid].startCol > startCol) { | ||
end = mid - 1 | ||
} else { | ||
start = mid + 1 | ||
} | ||
} | ||
if (start === end) { | ||
while (end < lines.length && extStartCol < lines[end].endCol && endCol >= lines[end].startCol) { | ||
++end | ||
} | ||
return lines.slice(start, end) | ||
} else { | ||
return [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* global describe, it */ | ||
const { sliceRange } = require('../lib/range') | ||
|
||
require('tap').mochaGlobals() | ||
require('should') | ||
|
||
describe('range', () => { | ||
describe('slice range', () => { | ||
it('can deal with empty arrays', () => { | ||
sliceRange([], 0, 1).should.eql([]) | ||
}) | ||
it('can find lines that match exactly', () => { | ||
const THREE_LINES = [ | ||
{ startCol: 0, endCol: 10 }, | ||
{ startCol: 11, endCol: 20 }, | ||
{ startCol: 21, endCol: 30 } | ||
] | ||
sliceRange(THREE_LINES, 0, 10).should.eql([THREE_LINES[0]]) | ||
sliceRange(THREE_LINES, 11, 20).should.eql([THREE_LINES[1]]) | ||
sliceRange(THREE_LINES, 21, 30).should.eql([THREE_LINES[2]]) | ||
}) | ||
it('can cover a range that spans two lines', () => { | ||
const SIX_LINES = [ | ||
{ startCol: 0, endCol: 3 }, | ||
{ startCol: 4, endCol: 10 }, | ||
{ startCol: 11, endCol: 14 }, | ||
{ startCol: 15, endCol: 20 }, | ||
{ startCol: 21, endCol: 24 }, | ||
{ startCol: 25, endCol: 30 } | ||
] | ||
sliceRange(SIX_LINES, 5, 14).should.eql(SIX_LINES.slice(1, 3)) | ||
sliceRange(SIX_LINES, 15, 21).should.eql(SIX_LINES.slice(3, 5)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters