Skip to content

Commit

Permalink
Merge pull request jashkenas#3497 from akre54/no-length-cache
Browse files Browse the repository at this point in the history
Remove the micro-opt of caching array length
  • Loading branch information
jashkenas committed Mar 4, 2015
2 parents da98d9e + 659acb1 commit 52973d3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@
var i = 0, names, length;
if (name && typeof name === 'object') {
// Handle event maps.
for (names = _.keys(name), length = names.length; i < length; i++) {
for (names = _.keys(name); i < names.length; i++) {
memo = iteratee(memo, names[i], name[names[i]], context, ctx);
}
} else if (name && eventSplitter.test(name)) {
// Handle space separated event names.
for (names = name.split(eventSplitter), length = names.length; i < length; i++) {
for (names = name.split(eventSplitter); i < names.length; i++) {
memo = iteratee(memo, names[i], callback, context, ctx);
}
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@
// is passed, narrow down the search to just that listener.
var ids = context != null ? [context._listenId] : _.keys(listeners);

for (var i = 0, length = ids.length; i < length; i++) {
for (var i = 0; i < ids.length; i++) {
var listener = listeners[ids[i]];

// Bail out if listener isn't listening.
Expand Down Expand Up @@ -185,7 +185,7 @@
if (!events || !name && !context && !callback) return;

var names = name ? [name] : _.keys(events);
for (var i = 0, length = names.length; i < length; i++) {
for (var i = 0; i < names.length; i++) {
name = names[i];
var handlers = events[name];

Expand Down Expand Up @@ -220,7 +220,7 @@
var internalStopListening = function(listener, obj, name, callback, offEvents) {
var listeningTo = listener._listeningTo;
var ids = obj ? [obj._listenId] : _.keys(listeningTo);
for (var i = 0, length = ids.length; i < length; i++) {
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
var listening = listeningTo[id];

Expand Down Expand Up @@ -475,7 +475,7 @@
// Trigger all relevant attribute changes.
if (!silent) {
if (changes.length) this._pending = options;
for (var i = 0, length = changes.length; i < length; i++) {
for (var i = 0; i < changes.length; i++) {
this.trigger('change:' + changes[i], this, current[changes[i]], options);
}
}
Expand Down Expand Up @@ -763,7 +763,7 @@
var singular = !_.isArray(models);
models = singular ? [models] : _.clone(models);
options || (options = {});
for (var i = 0, length = models.length; i < length; i++) {
for (var i = 0; i < models.length; i++) {
var model = models[i] = this.get(models[i]);
if (!model) continue;
var id = this.modelId(model.attributes);
Expand Down Expand Up @@ -803,7 +803,7 @@

// Turn bare objects into model references, and prevent invalid models
// from being added.
for (var i = 0, length = models.length; i < length; i++) {
for (var i = 0; i < models.length; i++) {
attrs = models[i];

// If a duplicate is found, prevent it from being added and
Expand Down Expand Up @@ -842,7 +842,7 @@

// Remove nonexistent models if appropriate.
if (remove) {
for (var i = 0, length = this.length; i < length; i++) {
for (var i = 0; i < this.length; i++) {
if (!modelMap[(model = this.models[i]).cid]) toRemove.push(model);
}
if (toRemove.length) this.remove(toRemove, options);
Expand All @@ -853,13 +853,13 @@
if (sortable) sort = true;
this.length += toAdd.length;
if (at != null) {
for (var i = 0, length = toAdd.length; i < length; i++) {
for (var i = 0; i < toAdd.length; i++) {
this.models.splice(at + i, 0, toAdd[i]);
}
} else {
if (order) this.models.length = 0;
var orderedModels = order || toAdd;
for (var i = 0, length = orderedModels.length; i < length; i++) {
for (var i = 0; i < orderedModels.length; i++) {
this.models.push(orderedModels[i]);
}
}
Expand All @@ -871,7 +871,7 @@
// Unless silenced, it's time to fire all appropriate add/sort events.
if (!options.silent) {
var addOpts = at != null ? _.clone(options) : options;
for (var i = 0, length = toAdd.length; i < length; i++) {
for (var i = 0; i < toAdd.length; i++) {
if (at != null) addOpts.index = at + i;
(model = toAdd[i]).trigger('add', model, this, addOpts);
}
Expand All @@ -888,7 +888,7 @@
// Useful for bulk operations and optimizations.
reset: function(models, options) {
options = options ? _.clone(options) : {};
for (var i = 0, length = this.models.length; i < length; i++) {
for (var i = 0; i < this.models.length; i++) {
this._removeReference(this.models[i], options);
}
options.previousModels = this.models;
Expand Down

0 comments on commit 52973d3

Please sign in to comment.