Skip to content

Commit

Permalink
Just made a few loop optimizations for Array loops
Browse files Browse the repository at this point in the history
  • Loading branch information
larzconwell committed Jul 25, 2012
1 parent 693a0fe commit 26600c5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
9 changes: 5 additions & 4 deletions lib/app.js
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions lib/base_controller.js
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand All @@ -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 == '*/*') {
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions lib/template/helpers/utils.js
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/template/index.js
Expand Up @@ -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);
Expand All @@ -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))

Expand Down
6 changes: 4 additions & 2 deletions lib/utils/string.js
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion templates/Jakefile
Expand Up @@ -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]*:?/, '');
Expand Down

0 comments on commit 26600c5

Please sign in to comment.