mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
Pass context to .forEach instead of closure
Has a slight performance improvement closes #2347
This commit is contained in:
parent
e9539fc780
commit
dfa7ee4732
|
|
@ -154,7 +154,6 @@ app.handle = function(req, res, done) {
|
|||
app.use = function use(fn) {
|
||||
var offset = 0;
|
||||
var path = '/';
|
||||
var self = this;
|
||||
|
||||
// default path to '/'
|
||||
// disambiguate app.use([fn])
|
||||
|
|
@ -190,7 +189,7 @@ app.use = function use(fn) {
|
|||
|
||||
debug('.use app under %s', path);
|
||||
fn.mountpath = path;
|
||||
fn.parent = self;
|
||||
fn.parent = this;
|
||||
|
||||
// restore .app property on req and res
|
||||
router.use(path, function mounted_app(req, res, next) {
|
||||
|
|
@ -203,8 +202,8 @@ app.use = function use(fn) {
|
|||
});
|
||||
|
||||
// mounted an app
|
||||
fn.emit('mount', self);
|
||||
});
|
||||
fn.emit('mount', this);
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
@ -278,17 +277,16 @@ app.engine = function(ext, fn){
|
|||
*/
|
||||
|
||||
app.param = function(name, fn){
|
||||
var self = this;
|
||||
self.lazyrouter();
|
||||
this.lazyrouter();
|
||||
|
||||
if (Array.isArray(name)) {
|
||||
name.forEach(function(key) {
|
||||
self.param(key, fn);
|
||||
});
|
||||
this.param(key, fn);
|
||||
}, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
self._router.param(name, fn);
|
||||
this._router.param(name, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -409,7 +409,6 @@ proto.process_params = function(layer, called, req, res, done) {
|
|||
proto.use = function use(fn) {
|
||||
var offset = 0;
|
||||
var path = '/';
|
||||
var self = this;
|
||||
|
||||
// default path to '/'
|
||||
// disambiguate router.use([fn])
|
||||
|
|
@ -442,15 +441,15 @@ proto.use = function use(fn) {
|
|||
debug('use %s %s', path, fn.name || '<anonymous>');
|
||||
|
||||
var layer = new Layer(path, {
|
||||
sensitive: self.caseSensitive,
|
||||
sensitive: this.caseSensitive,
|
||||
strict: false,
|
||||
end: false
|
||||
}, fn);
|
||||
|
||||
layer.route = undefined;
|
||||
|
||||
self.stack.push(layer);
|
||||
});
|
||||
this.stack.push(layer);
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ Route.prototype.dispatch = function(req, res, done){
|
|||
*/
|
||||
|
||||
Route.prototype.all = function(){
|
||||
var self = this;
|
||||
var callbacks = utils.flatten([].slice.call(arguments));
|
||||
callbacks.forEach(function(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
|
|
@ -143,16 +142,15 @@ Route.prototype.all = function(){
|
|||
var layer = Layer('/', {}, fn);
|
||||
layer.method = undefined;
|
||||
|
||||
self.methods._all = true;
|
||||
self.stack.push(layer);
|
||||
});
|
||||
this.methods._all = true;
|
||||
this.stack.push(layer);
|
||||
}, this);
|
||||
|
||||
return self;
|
||||
return this;
|
||||
};
|
||||
|
||||
methods.forEach(function(method){
|
||||
Route.prototype[method] = function(){
|
||||
var self = this;
|
||||
var callbacks = utils.flatten([].slice.call(arguments));
|
||||
|
||||
callbacks.forEach(function(fn) {
|
||||
|
|
@ -162,14 +160,14 @@ methods.forEach(function(method){
|
|||
throw new Error(msg);
|
||||
}
|
||||
|
||||
debug('%s %s', method, self.path);
|
||||
debug('%s %s', method, this.path);
|
||||
|
||||
var layer = Layer('/', {}, fn);
|
||||
layer.method = method;
|
||||
|
||||
self.methods[method] = true;
|
||||
self.stack.push(layer);
|
||||
});
|
||||
return self;
|
||||
this.methods[method] = true;
|
||||
this.stack.push(layer);
|
||||
}, this);
|
||||
return this;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user