Skip to content
Myr

optimize res.format()

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

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 812a470 · Browse files · 1 file+9 added−6 removed
This commit

State

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

Diff stats

1 file+9 added−6 removed

  • other:+9 added−6 removed

1 file+9 added−6 removed

modified:lib/response.js+9 added-6 removed
342 unmodified lines
343 , types = []344 , req = this.req345 , next = req.next346 , accepted = req.accepted347 , acceptedlen = accepted.length348 , type349 , key;350351 // normalize extnames -> mime352 if (acceptedlen) {351 for (var i = 0; i < keys.length; ++i) {352 types.push(~keys[i].indexOf('/')353 ? keys[i]354 : mime.lookup(keys[i]));353 for (var i = 0; i < keys.length; ++i) {354 types.push(~keys[i].indexOf('/')355 ? keys[i]356 : mime.lookup(keys[i]));357 }358 }359360 // determine most acceptable format361 out:359 for (var i = 0, len = accepted.length; i < len; ++i) {362 for (var i = 0; i < acceptedlen; ++i) {363 for (var j = 0, jlen = types.length; j < jlen; ++j) {364 if (accept(types[j].split('/'), accepted[i])) {365 key = keys[j];366 type = types[j];
2 unmodified lines
369 }370 }371372 // default to the first370 if (!accepted.length) {373 if (!acceptedlen) {374 key = keys[0];375 type = types[0];376 }377
288 unmodified lines