Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add duffs

  • Loading branch information...
commit ff3aacfe1f046dfc09c24965e1928db5620fe9e1 1 parent e54d4a5
@isaacs authored
Showing with 39 additions and 2 deletions.
  1. +20 −2 examples/array-ify-offset.js
  2. +19 −0 examples/array-ify.js
View
22 examples/array-ify-offset.js
@@ -1,15 +1,30 @@
// testing converting arguments to an Array
+function duff () {
+ var l = arguments.length
+ var arr = new Array(l - 1)
+ switch (l) {
+ case 8: arr[6] = arguments[7]
+ case 7: arr[5] = arguments[6]
+ case 6: arr[4] = arguments[5]
+ case 5: arr[3] = arguments[4]
+ case 4: arr[2] = arguments[3]
+ case 3: arr[1] = arguments[2]
+ case 2: arr[0] = arguments[1]
+ }
+ return arr
+}
+
function manualMap () {
var l = arguments.length
- var arr = new Array(l)
+ var arr = new Array(l - 1)
for (var i = 1; i < l; i ++) arr[i - 1] = arguments[i]
return arr
}
function manualMapArg (x) {
var l = arguments.length
- var arr = new Array(l)
+ var arr = new Array(l - 1)
for (var i = 1; i < l; i ++) arr[i - 1] = arguments[i]
return arr
}
@@ -67,6 +82,9 @@ exports.compare =
, sliceApplyArg: function () {
return [ sliceApplyArg(Math.random()), sliceApplyArg(Math.random(), Math.random()) ]
}
+ , duff: function () {
+ return [ duff(Math.random()), duff(Math.random(), Math.random()) ]
+ }
}
exports.countPerLap = 2
View
19 examples/array-ify.js
@@ -14,6 +14,22 @@ function manualMapArg (x) {
return arr
}
+function duff () {
+ var l = arguments.length
+ var arr = new Array(l)
+ switch (l) {
+ case 8: arr[7] = arguments[7]
+ case 7: arr[6] = arguments[6]
+ case 6: arr[5] = arguments[5]
+ case 5: arr[4] = arguments[4]
+ case 4: arr[3] = arguments[3]
+ case 3: arr[2] = arguments[2]
+ case 2: arr[1] = arguments[1]
+ case 1: arr[0] = arguments[0]
+ }
+ return arr
+}
+
function arrayApply () {
return arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments)
}
@@ -58,6 +74,9 @@ exports.compare =
{ manualMap: function () {
return [ manualMap(Math.random()), manualMap(Math.random(), Math.random()) ]
}
+ , duff: function () {
+ return [ duff(Math.random()), duff(Math.random(), Math.random()) ]
+ }
, manualMapArg: function () {
return [ manualMapArg(Math.random()), manualMapArg(Math.random(), Math.random()) ]
}
Please sign in to comment.
Something went wrong with that request. Please try again.