Skip to content

Commit e6bfd66

Browse files
committed
Split d3_array into d3_arrayNodes and d3_arrayArguments.
1 parent fe5fdb3 commit e6bfd66

3 files changed

Lines changed: 15 additions & 31 deletions

File tree

src/core/array.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
1-
function d3_array(psuedoarray) {
1+
var d3_arrayArguments = d3_arraySlice, // conversion for arguments
2+
d3_arrayNodes = d3_arraySlice; // conversion for NodeLists
3+
4+
function d3_arraySlow(psuedoarray) {
5+
var i = -1, n = psuedoarray.length, array = [];
6+
while (++i < n) array.push(psuedoarray[i]);
7+
return array;
8+
}
9+
10+
function d3_arraySlice(psuedoarray) {
211
return Array.prototype.slice.call(psuedoarray);
312
}
413

5-
// Adapted from Sizzle.js:
6-
//
7-
// Perform a simple check to determine if the browser is capable of
8-
// converting a NodeList to an array using builtin methods.
9-
// Also verifies that the returned array holds DOM nodes
10-
// (which is not the case in the Blackberry browser)
1114
try {
12-
Array.prototype.slice.call(document.documentElement.childNodes, 0)[0].nodeType;
13-
// Provide a fallback method if it does not work
15+
d3_arrayNodes(document.documentElement.childNodes)[0].nodeType;
1416
} catch(e) {
15-
d3_array = function(array) {
16-
var i = 0,
17-
ret = [];
18-
19-
if (toString.call(array) === "[object Array]") {
20-
Array.prototype.push.apply(ret, array);
21-
} else {
22-
if (typeof array.length === "number") {
23-
for (var l = array.length; i < l; i++) {
24-
ret.push(array[i]);
25-
}
26-
} else {
27-
for (; array[i]; i++) {
28-
ret.push(array[i]);
29-
}
30-
}
31-
}
32-
return ret;
33-
};
17+
d3_arrayNodes = d3_arraySlow;
3418
}

src/core/call.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function d3_call(callback, var_args) {
2-
var_args = d3_array(arguments);
2+
var_args = d3_arrayArguments(arguments);
33
var_args[0] = this;
44
callback.apply(this, var_args);
55
return this;

src/core/selection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var d3_select = function(s, n) { return n.querySelector(s); },
2-
d3_selectAll = function(s, n) { return d3_array(n.querySelectorAll(s)); };
2+
d3_selectAll = function(s, n) { return d3_arrayNodes(n.querySelectorAll(s)); };
33

44
// Use Sizzle, if available.
55
if (typeof Sizzle == "function") {
@@ -20,7 +20,7 @@ d3.select = function(selector) {
2020
d3.selectAll = function(selector) {
2121
return typeof selector == "string"
2222
? d3_root.selectAll(selector)
23-
: d3_selection([d3_array(selector)]); // assume node[]
23+
: d3_selection([d3_arrayNodes(selector)]); // assume node[]
2424
};
2525

2626
function d3_selection(groups) {

0 commit comments

Comments
 (0)