Skip to content

Commit 341ad30

Browse files
committed
Restore only the essence of former optimizeCb
1 parent 640332b commit 341ad30

File tree

7 files changed

+57
-14
lines changed

7 files changed

+57
-14
lines changed

modules/_bindCb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Internal function that returns a bound version of the passed-in callback, to
2-
// be repeatedly applied in other Underscore functions.
1+
// Internal function that returns a bound version of the
2+
// passed-in callback, used in `_.iteratee`.
33
export default function bindCb(func, context) {
44
if (context === void 0) return func;
55
return function() {

modules/_bindCb4.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// In Firefox, `Function.prototype.call` is faster than
2+
// `Function.prototype.apply`. In the optimized variant of
3+
// `bindCb` below, we exploit the fact that no Underscore
4+
// function passes more than four arguments to a callback.
5+
// **NOT general enough for use outside of Underscore.**
6+
export default function bindCb4(func, context) {
7+
if (context === void 0) return func;
8+
return function(a1, a2, a3, a4) {
9+
return func.call(context, a1, a2, a3, a4);
10+
};
11+
}

modules/_cb.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import isFunction from './isFunction.js';
2+
import bindCb4 from './_bindCb4.js';
13
import _ from './underscore.js';
24
import './iteratee.js';
35

4-
// The function we call internally to generate a callback. It is just a
5-
// shorthand to save some bytes in the minified code.
6+
// The function we call internally to generate a callback: a wrapper
7+
// of `_.iteratee`, which uses `bindCb4` instead of `bindCb` for
8+
// function iteratees. It also saves some bytes in the minified code.
69
export default function cb(value, context) {
10+
if (isFunction(value)) return bindCb4(value, context);
711
return _.iteratee(value, context);
812
}

underscore-esm.js

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

underscore-esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

underscore.js

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

underscore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)