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:
Родитель
4adb0c24f5
Коммит
500538afe2
|
@ -5624,8 +5624,8 @@
|
||||||
bs = b.substring(bi, bs);
|
bs = b.substring(bi, bs);
|
||||||
if (s[i]) s[i] += bs; else s[++i] = bs;
|
if (s[i]) s[i] += bs; else s[++i] = bs;
|
||||||
}
|
}
|
||||||
if ((am = +am[0]) === (bm = +(bs = bm[0]))) {
|
if ((am = am[0]) === (bm = bm[0])) {
|
||||||
if (s[i]) s[i] += bs; else s[++i] = bs;
|
if (s[i]) s[i] += bm; else s[++i] = bm;
|
||||||
} else {
|
} else {
|
||||||
s[++i] = null;
|
s[++i] = null;
|
||||||
q.push({
|
q.push({
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -22,9 +22,9 @@ function d3_interpolateString(a, b) {
|
||||||
if (s[i]) s[i] += bs; // coalesce with previous string
|
if (s[i]) s[i] += bs; // coalesce with previous string
|
||||||
else s[++i] = bs;
|
else s[++i] = bs;
|
||||||
}
|
}
|
||||||
if ((am = +am[0]) === (bm = +(bs = bm[0]))) { // coalesce matching numbers
|
if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
|
||||||
if (s[i]) s[i] += bs; // coalesce with previous string
|
if (s[i]) s[i] += bm; // coalesce with previous string
|
||||||
else s[++i] = bs;
|
else s[++i] = bm;
|
||||||
} else { // interpolate non-matching numbers
|
} else { // interpolate non-matching numbers
|
||||||
s[++i] = null;
|
s[++i] = null;
|
||||||
q.push({i: i, x: d3_interpolateNumber(am, bm)});
|
q.push({i: i, x: d3_interpolateNumber(am, bm)});
|
||||||
|
|
|
@ -43,8 +43,9 @@ suite.addBatch({
|
||||||
assert.strictEqual(interpolate("", "bar")(.5), "bar");
|
assert.strictEqual(interpolate("", "bar")(.5), "bar");
|
||||||
assert.strictEqual(interpolate("", "")(.5), "");
|
assert.strictEqual(interpolate("", "")(.5), "");
|
||||||
},
|
},
|
||||||
"with two numerically-equivalent numbers, returns the target format": function(interpolate) {
|
"with two numerically-equivalent numbers, returns the default format": function(interpolate) {
|
||||||
assert.strictEqual(interpolate("top: 1000px;", "top: 1e3px;")(.5), "top: 1e3px;");
|
assert.strictEqual(interpolate("top: 1000px;", "top: 1e3px;")(.5), "top: 1000px;");
|
||||||
|
assert.strictEqual(interpolate("top: 1e3px;", "top: 1000px;")(.5), "top: 1000px;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче