Skip to content
Myr

Pass context to .forEach instead of closure

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Has a slight performance improvement closes #2347

authored by lemmy · committed by Douglas Christopher Wilson · parent e9539fc · Browse files · 3 files+19 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+19 added−24 removed

  • other:+19 added−24 removed

3 files+19 added−24 removed

modified:lib/router/index.js+3 added-4 removed
407 unmodified lines
408409proto.use = function use(fn) {410 var offset = 0;411 var path = '/';412 var self = this;412413 // default path to '/'414 // disambiguate router.use([fn])415 if (typeof fn !== 'function') {
24 unmodified lines
440 // add the middleware441 debug('use %s %s', path, fn.name || '<anonymous>');442443 var layer = new Layer(path, {445 sensitive: self.caseSensitive,444 sensitive: this.caseSensitive,445 strict: false,446 end: false447 }, fn);448449 layer.route = undefined;450452 self.stack.push(layer);453 });451 this.stack.push(layer);452 }, this);453454 return this;455};456
119 unmodified lines
modified:lib/router/route.js+9 added-11 removed
modified:lib/application.js+7 added-9 removed
152 unmodified lines
153154app.use = function use(fn) {155 var offset = 0;156 var path = '/';157 var self = this;157158 // default path to '/'159 // disambiguate app.use([fn])160 if (typeof fn !== 'function') {
27 unmodified lines
188 }189190 debug('.use app under %s', path);191 fn.mountpath = path;193 fn.parent = self;192 fn.parent = this;193194 // restore .app property on req and res195 router.use(path, function mounted_app(req, res, next) {196 var orig = req.app;
4 unmodified lines
201 });202 });203204 // mounted an app206 fn.emit('mount', self);207 });205 fn.emit('mount', this);206 }, this);207208 return this;209};210
65 unmodified lines
276 * @api public277 */278279app.param = function(name, fn){281 var self = this;282 self.lazyrouter();280 this.lazyrouter();281282 if (Array.isArray(name)) {283 name.forEach(function(key) {286 self.param(key, fn);287 });284 this.param(key, fn);285 }, this);286 return this;287 }288291 self._router.param(name, fn);289 this._router.param(name, fn);290 return this;291};292293/**
275 unmodified lines