Skip to content

Commit

Permalink
Remove usage of d3_array for efficiency.
Browse files Browse the repository at this point in the history
This avoids unnecessarily creating a new array for every touch event.
  • Loading branch information
jasondavies committed May 12, 2011
1 parent a5f1407 commit 1bb3e9b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions d3.js
Expand Up @@ -3183,7 +3183,11 @@ function d3_svg_mousePoints(container, events) {
d3_mouse_bug44083 = !(ctm.f || ctm.e);
svg.remove();
}
return events.map(function(e) {
var i = -1,
n = events.length,
points = [];
while (++i < n) {
var e = events[i];
if (d3_mouse_bug44083) {
point.x = e.pageX;
point.y = e.pageY;
Expand All @@ -3192,13 +3196,14 @@ function d3_svg_mousePoints(container, events) {
point.y = e.clientY;
}
point = point.matrixTransform(container.getScreenCTM().inverse());
return [point.x, point.y];
});
points.push([point.x, point.y]);
}
return points;
};
d3.svg.touches = function(container) {
var touches = d3.event.touches;
return touches && touches.length
? d3_svg_mousePoints(container, d3_array(touches)) : [];
? d3_svg_mousePoints(container, touches) : [];
};
d3.svg.symbol = function() {
var type = d3_svg_symbolType,
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/svg/mouse.js
Expand Up @@ -17,7 +17,11 @@ function d3_svg_mousePoints(container, events) {
d3_mouse_bug44083 = !(ctm.f || ctm.e);
svg.remove();
}
return events.map(function(e) {
var i = -1,
n = events.length,
points = [];
while (++i < n) {
var e = events[i];
if (d3_mouse_bug44083) {
point.x = e.pageX;
point.y = e.pageY;
Expand All @@ -26,6 +30,7 @@ function d3_svg_mousePoints(container, events) {
point.y = e.clientY;
}
point = point.matrixTransform(container.getScreenCTM().inverse());
return [point.x, point.y];
});
points.push([point.x, point.y]);
}
return points;
};
2 changes: 1 addition & 1 deletion src/svg/touches.js
@@ -1,5 +1,5 @@
d3.svg.touches = function(container) {
var touches = d3.event.touches;
return touches && touches.length
? d3_svg_mousePoints(container, d3_array(touches)) : [];
? d3_svg_mousePoints(container, touches) : [];
};

0 comments on commit 1bb3e9b

Please sign in to comment.