Browse Source

Improve row skipping performance (#911) (#912)

Co-authored-by: Aleks Bezrodnov <aleksei.bezrodnov@zalando.de>
master
bezrodnov 3 years ago committed by GitHub
parent
commit
a93c5c9806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      papaparse.js
  2. 29
      tests/test-cases.js

6
papaparse.js

@ -1163,9 +1163,9 @@ License: MIT
if (_config.skipEmptyLines) if (_config.skipEmptyLines)
{ {
for (var i = 0; i < _results.data.length; i++) _results.data = _results.data.filter(function(d) {
if (testEmptyLine(_results.data[i])) return !testEmptyLine(d);
_results.data.splice(i--, 1); });
} }
if (needsHeaderRow()) if (needsHeaderRow())

29
tests/test-cases.js

@ -1608,6 +1608,31 @@ var PARSE_ASYNC_TESTS = [
data: [['A','B','C'],['X','Y','Z']], data: [['A','B','C'],['X','Y','Z']],
errors: [] errors: []
} }
},
{
description: "File with a few regular and lots of empty lines",
disabled: !FILES_ENABLED,
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z\n" + new Array(500000).fill(",,").join("\n")], "sample.csv") : false,
config: {
skipEmptyLines: "greedy"
},
expected: {
data: [['A','B','C'],['X','Y','Z']],
errors: []
}
},
{
description: "File with a few regular and lots of empty lines + worker",
disabled: !FILES_ENABLED,
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z\n" + new Array(500000).fill(",,").join("\n")], "sample.csv") : false,
config: {
worker: true,
skipEmptyLines: "greedy"
},
expected: {
data: [['A','B','C'],['X','Y','Z']],
errors: []
}
} }
]; ];
@ -1836,9 +1861,9 @@ var UNPARSE_TESTS = [
}, },
{ {
description: "Returns without rows with no content when skipEmptyLines is 'greedy'", description: "Returns without rows with no content when skipEmptyLines is 'greedy'",
input: [[null, ' '], [], ['1', '2']], input: [[null, ' '], [], ['1', '2']].concat(new Array(500000).fill(['', ''])).concat([['3', '4']]),
config: {skipEmptyLines: 'greedy'}, config: {skipEmptyLines: 'greedy'},
expected: '1,2' expected: '1,2\r\n3,4'
}, },
{ {
description: "Returns empty rows when empty rows are passed and skipEmptyLines is false with headers", description: "Returns empty rows when empty rows are passed and skipEmptyLines is false with headers",

Loading…
Cancel
Save