Skip to content

Commit 197ff6b

Browse files
committed
Optimize csv.parse slightly.
1 parent 4e6dc7c commit 197ff6b

6 files changed

Lines changed: 17 additions & 27 deletions

File tree

d3.csv.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,15 @@ d3.csv.parseRows = function(text, f) {
3333

3434
// special case: quotes
3535
var j = re.lastIndex;
36-
if (text.charAt(j) == "\"") {
36+
if (text.charCodeAt(j) == 34) {
3737
var i = j;
38-
out: while (i++ < text.length) {
39-
switch (text.charAt(i)) {
40-
case "\"": {
41-
if (text.charAt(i + 1) == "\"") {
42-
i++;
43-
break;
44-
}
45-
break out;
46-
}
38+
while (i++ < text.length) {
39+
if (text.charCodeAt(i) == 34) {
40+
if (text.charCodeAt(i + 1) != 34) break;
41+
i++;
4742
}
4843
}
49-
if (text.charAt(i + 1) == "\n") eol = true;
44+
if (text.charCodeAt(i + 1) == 10) eol = true;
5045
re.lastIndex = i + 2;
5146
return text.substring(j + 1, i).replace(/""/g, "\"");
5247
}

d3.csv.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
d3 = {version: "0.12.0"}; // semver
1+
d3 = {version: "0.12.1"}; // semver
22
if (!Date.now) Date.now = function() {
33
return +new Date();
44
};

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3 = {version: "0.12.0"}; // semver
1+
d3 = {version: "0.12.1"}; // semver

src/csv/parse.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,15 @@ d3.csv.parseRows = function(text, f) {
2828

2929
// special case: quotes
3030
var j = re.lastIndex;
31-
if (text.charAt(j) == "\"") {
31+
if (text.charCodeAt(j) == 34) {
3232
var i = j;
33-
out: while (i++ < text.length) {
34-
switch (text.charAt(i)) {
35-
case "\"": {
36-
if (text.charAt(i + 1) == "\"") {
37-
i++;
38-
break;
39-
}
40-
break out;
41-
}
33+
while (i++ < text.length) {
34+
if (text.charCodeAt(i) == 34) {
35+
if (text.charCodeAt(i + 1) != 34) break;
36+
i++;
4237
}
4338
}
44-
if (text.charAt(i + 1) == "\n") eol = true;
39+
if (text.charCodeAt(i + 1) == 10) eol = true;
4540
re.lastIndex = i + 2;
4641
return text.substring(j + 1, i).replace(/""/g, "\"");
4742
}

0 commit comments

Comments
 (0)