perf: remove argument reassignments in View
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 0634e7e · Browse files · 2 files·+48 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+48 added−26 removed
- other:+48 added−26 removed
Provenance
- Commit
a8a8564- Tree
d6e6aa6- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
0634e7e
2 files changed+48 added−26 removed
modified:lib/view.js+47 added-26 removed
8 unmodified lines9101112131415161711 unmodified lines29303132323334353637385 unmodified lines444546474647484849505152535254555657585455565758596061596061626364656667686970717273747576777879808182838485868788899067686991929394959616 unmodified lines113114115116941171189697981191201211221231011241251031261271281291304 unmodified lines13513613713811611713914012012114114214314414514627 unmodified lines8 unmodified lines'use strict';
/** * Module dependencies. * @private */
var debug = require('debug')('express:view');var path = require('path');11 unmodified linesvar join = path.join;var resolve = path.resolve;
/** * Expose `View`. * Module exports. * @public */
module.exports = View;
5 unmodified lines * - `defaultEngine` the default template engine name * - `engines` template engine require() cache * - `root` root path for view lookup * * @param {String} name * @param {Object} options * @api private * @param {string} name * @param {object} options * @public */
function View(name, options) { options = options || {}; var opts = options || {};
this.defaultEngine = opts.defaultEngine; this.ext = extname(name); this.name = name; this.root = options.root; var engines = options.engines; this.defaultEngine = options.defaultEngine; var ext = this.ext = extname(name); if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.'); if (!ext) name += (ext = this.ext = ('.' != this.defaultEngine[0] ? '.' : '') + this.defaultEngine); this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express); this.path = this.lookup(name); this.root = opts.root;
if (!this.ext && !this.defaultEngine) { throw new Error('No default engine was specified and no extension was provided.'); }
var fileName = name;
if (!this.ext) { // get extension from default engine name this.ext = this.defaultEngine[0] !== '.' ? '.' + this.defaultEngine : this.defaultEngine;
fileName += this.ext; }
if (!opts.engines[this.ext]) { // load engine opts.engines[this.ext] = require(this.ext.substr(1)).__express; }
// store loaded engine this.engine = opts.engines[this.ext];
// lookup path this.path = this.lookup(fileName);}
/** * Lookup view by the given `name` * * @param {String} name * @return {String} * @api private * @param {string} name * @private */
View.prototype.lookup = function lookup(name) { var path;16 unmodified lines return path;};
/** * Render with the given `options` and callback `fn(err, str)`. * Render with the given options. * * @param {Object} options * @param {Function} fn * @api private * @param {object} options * @param {function} callback * @private */
View.prototype.render = function render(options, fn) {View.prototype.render = function render(options, callback) { debug('render "%s"', this.path); this.engine(this.path, options, fn); this.engine(this.path, options, callback);};
/** * Resolve the file within the given directory.4 unmodified lines */
View.prototype.resolve = function resolve(dir, file) { var ext = this.ext; var path; var stat;
// <path>.<ext> path = join(dir, file); stat = tryStat(path); var path = join(dir, file); var stat = tryStat(path);
if (stat && stat.isFile()) { return path; }27 unmodified linesmodified:History.md+1 added
64 unmodified lines65 - deps: mime-types@~2.1.166 - perf: reduce try block size67 - perf: remove bitwise operations68 * perf: enable strict mode69+ * perf: remove argument reassignments in `View`70 * perf: use saved reference to `http.STATUS_CODES`71 72 4.12.4 / 2015-05-1773 ===================2881 unmodified lines