Permalink
Browse files
Just made a few loop optimizations for Array loops
- Loading branch information...
|
@@ -197,11 +197,11 @@ var App = function () { |
|
|
this.router = router;
|
|
|
|
|
|
// Create action helpers based on router
|
|
|
- for(var i in router.routes) {
|
|
|
+ var i = router.routes.length;
|
|
|
+ while(--i >= 0) {
|
|
|
actionHelpers.create(router.routes[i].params);
|
|
|
}
|
|
|
actionHelpers.add(helpers); // Add action helpers to helpers
|
|
|
-
|
|
|
next();
|
|
|
}
|
|
|
|
|
@@ -328,9 +328,10 @@ var App = function () { |
|
|
, fileName
|
|
|
, fileExt
|
|
|
, fileBaseName
|
|
|
- , usingCoffee;
|
|
|
+ , usingCoffee
|
|
|
+ , i = dirList.length;
|
|
|
|
|
|
- for(var i = 0; i < dirList.length; i++) {
|
|
|
+ while(--i >= 0) {
|
|
|
fileName = dirList[i];
|
|
|
fileExt = path.extname(fileName);
|
|
|
fileBaseName = path.basename(fileName, fileExt);
|
|
|
|
@@ -140,14 +140,15 @@ controller.BaseController.prototype = new (function () { |
|
|
, list = []
|
|
|
, applyFilter = true // Default
|
|
|
, filter
|
|
|
- , func;
|
|
|
+ , func
|
|
|
+ , i;
|
|
|
|
|
|
if(!filters) {
|
|
|
callback();
|
|
|
- return; // Not sure if we need this since we're calling a function above
|
|
|
}
|
|
|
|
|
|
- for(var i = 0, len = filters.length; i < len; i++) {
|
|
|
+ i = filters.length;
|
|
|
+ while(--i >= 0) {
|
|
|
filter = filters[i];
|
|
|
|
|
|
if(filter.only && (filter.only != action || filter.only.indexOf(action) == -1)) {
|
|
@@ -194,7 +195,8 @@ controller.BaseController.prototype = new (function () { |
|
|
, match
|
|
|
, err
|
|
|
, accept
|
|
|
- , pat;
|
|
|
+ , pat
|
|
|
+ , i;
|
|
|
|
|
|
// If client provides an Accept header, split on comma
|
|
|
// - some user-agents include whitespace with the comma
|
|
@@ -220,7 +222,8 @@ controller.BaseController.prototype = new (function () { |
|
|
|
|
|
// See if any format types match
|
|
|
if(types.length) {
|
|
|
- for(var i = 0, len = accepts.length; i < len; i++) {
|
|
|
+ i = accepts.length;
|
|
|
+ while(--i >= 0) {
|
|
|
accept = accepts[i].split(';')[0]; // Ignore quality factors
|
|
|
|
|
|
if(accept == '*/*') {
|
|
@@ -244,7 +247,8 @@ controller.BaseController.prototype = new (function () { |
|
|
}
|
|
|
// Otherwise look through acceptable formats and see if Geddy knows about them
|
|
|
else {
|
|
|
- for(var i = 0, len = types.length; i< len; i++) {
|
|
|
+ i = types.length;
|
|
|
+ while(--i >= 0) {
|
|
|
match = response.matchAcceptHeaderContentType(accepts, types[i]);
|
|
|
|
|
|
if(match) {
|
|
|
|
@@ -314,14 +314,18 @@ exports.urls = { |
|
|
, i;
|
|
|
|
|
|
// Delete all other options
|
|
|
- for(i in this.supportedOptions) {
|
|
|
+ i = this.supportedOptions.length;
|
|
|
+ while(--i >= 0) {
|
|
|
delete options[this.supportedOptions[i]];
|
|
|
}
|
|
|
|
|
|
if(!utils.object.isEmpty(options)) {
|
|
|
options = utils.object.toArray(options);
|
|
|
|
|
|
- for(i in options) {
|
|
|
+
|
|
|
+ // Do positive while loop here to keep query items in order
|
|
|
+ i = -1;
|
|
|
+ while(++i < options.length) {
|
|
|
query += i == 0 ? '?' : '&';
|
|
|
query += this.escape(options[i].key) + '=' + this.escape(options[i].value);
|
|
|
}
|
|
|
|
@@ -155,7 +155,8 @@ getTemplateData = function(templateRoot, partialURL, parentNode, isLayout) { |
|
|
var dirs = []
|
|
|
, dir
|
|
|
, key
|
|
|
- , templateData;
|
|
|
+ , templateData
|
|
|
+ , i;
|
|
|
|
|
|
// If it's a sub template, then look in the parent's directory
|
|
|
if(parentNode) dirs.push(parentNode.dirname);
|
|
@@ -167,8 +168,8 @@ getTemplateData = function(templateRoot, partialURL, parentNode, isLayout) { |
|
|
// Loop through dirs until a registered template path is found
|
|
|
// Note: Template paths are gathered at init so we don't have to touch the FS
|
|
|
// - when looking for templates
|
|
|
- var i;
|
|
|
- for(i in dirs) {
|
|
|
+ i = dirs.length;
|
|
|
+ while(--i >= 0) {
|
|
|
dir = dirs[i];
|
|
|
key = path.normalize(dir + '/' + partialURL); // Not full path(No extension(s))
|
|
|
|
|
|
|
@@ -201,7 +201,8 @@ var inflection = require('../../deps/inflection') |
|
|
, result = pat.exec(string)
|
|
|
, item
|
|
|
, firstPos
|
|
|
- , lastPos;
|
|
|
+ , lastPos
|
|
|
+ , i;
|
|
|
|
|
|
// Gather the HTML tags and content into the array
|
|
|
while(result) {
|
|
@@ -225,7 +226,8 @@ var inflection = require('../../deps/inflection') |
|
|
|
|
|
// Loop through array items appending the tags to the string,
|
|
|
// - and truncating the text then appending it to content
|
|
|
- for(var i in arr) {
|
|
|
+ i = -1;
|
|
|
+ while(++i < arr.length) {
|
|
|
item = arr[i];
|
|
|
switch(true) {
|
|
|
// Closing tag
|
|
|
|
@@ -43,7 +43,8 @@ namespace('gen', function () { |
|
|
, i
|
|
|
, value;
|
|
|
|
|
|
- for(i in itemsArr) {
|
|
|
+ i = -1;
|
|
|
+ while(++i < itemsArr.length) {
|
|
|
value = itemsArr[i];
|
|
|
name = value.replace(/:.*/g, '');
|
|
|
type = value.replace(/[a-zA-Z]*:?/, '');
|
|
|
0 comments on commit
26600c5