Only coalesce exact string matches.

If there are a lot of matching numbers, it’s faster to do direct string equality
comparisons than it is to coerce to a number and compare numerically.
This commit is contained in:
Mike Bostock 2014-04-05 21:50:33 -07:00
Родитель 4adb0c24f5
Коммит 500538afe2
4 изменённых файлов: 9 добавлений и 8 удалений

4
d3.js поставляемый
Просмотреть файл

@ -5624,8 +5624,8 @@
bs = b.substring(bi, bs);
if (s[i]) s[i] += bs; else s[++i] = bs;
}
if ((am = +am[0]) === (bm = +(bs = bm[0]))) {
if (s[i]) s[i] += bs; else s[++i] = bs;
if ((am = am[0]) === (bm = bm[0])) {
if (s[i]) s[i] += bm; else s[++i] = bm;
} else {
s[++i] = null;
q.push({

2
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -22,9 +22,9 @@ function d3_interpolateString(a, b) {
if (s[i]) s[i] += bs; // coalesce with previous string
else s[++i] = bs;
}
if ((am = +am[0]) === (bm = +(bs = bm[0]))) { // coalesce matching numbers
if (s[i]) s[i] += bs; // coalesce with previous string
else s[++i] = bs;
if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
if (s[i]) s[i] += bm; // coalesce with previous string
else s[++i] = bm;
} else { // interpolate non-matching numbers
s[++i] = null;
q.push({i: i, x: d3_interpolateNumber(am, bm)});

Просмотреть файл

@ -43,8 +43,9 @@ suite.addBatch({
assert.strictEqual(interpolate("", "bar")(.5), "bar");
assert.strictEqual(interpolate("", "")(.5), "");
},
"with two numerically-equivalent numbers, returns the target format": function(interpolate) {
assert.strictEqual(interpolate("top: 1000px;", "top: 1e3px;")(.5), "top: 1e3px;");
"with two numerically-equivalent numbers, returns the default format": function(interpolate) {
assert.strictEqual(interpolate("top: 1000px;", "top: 1e3px;")(.5), "top: 1000px;");
assert.strictEqual(interpolate("top: 1e3px;", "top: 1000px;")(.5), "top: 1000px;");
}
}
});