Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Having a non-eval, non-observe path for getValueFrom isn't a perf win…
Browse files Browse the repository at this point in the history
…. Remove the extra code path.

R=arv
BUG=

Review URL: https://codereview.appspot.com/13139046
  • Loading branch information
rafaelw committed Aug 24, 2013
1 parent a7a8782 commit fae14aa
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
this.push(part);
}, this);

if (hasEval && this.length) {
if (hasEval && !hasObserve && this.length) {
this.getValueFrom = this.compiledGetValueFromFn();
}
}
Expand All @@ -148,24 +148,17 @@
return this.join('.');
},

getValueFrom: function(obj, allValues) {
for (var i = 0; i < this.length; i++) {
if (obj === undefined || obj === null)
return;
obj = obj[this[i]];
}

return obj;
},

getValueFromObserved: function(obj, observedSet) {
observedSet.reset();
getValueFrom: function(obj, observedSet) {
if (observedSet)
observedSet.reset();
for (var i = 0; i < this.length; i++) {
if (obj === undefined || obj === null) {
observedSet.cleanup();
if (observedSet)
observedSet.cleanup();
return;
}
observedSet.observe(obj);
if (observedSet)
observedSet.observe(obj);
obj = obj[this[i]];
}

Expand Down Expand Up @@ -543,10 +536,6 @@
});
};

function getPathValue(object, path) {
return path.getValueFrom(object);
}

function ObservedSet(callback) {
this.arr = [];
this.callback = callback;
Expand Down Expand Up @@ -634,16 +623,16 @@

disconnect: function() {
this.value = undefined;
if (hasObserve) {
if (this.observedSet) {
this.observedSet.reset();
this.observedSet.cleanup();
this.observedSet = undefined;
}
},

check: function() {
this.value = !hasObserve ? this.path.getValueFrom(this.object) :
this.path.getValueFromObserved(this.object, this.observedSet);
this.value = this.path.getValueFrom(this.object, this.observedSet);

if (areSameValue(this.value, this.oldValue))
return false;

Expand All @@ -652,10 +641,9 @@
},

sync: function(hard) {
if (hard) {
this.value = !hasObserve ? this.path.getValueFrom(this.object) :
this.path.getValueFromObserved(this.object, this.observedSet);
}
if (hard)
this.value = this.path.getValueFrom(this.object, this.observedSet);

this.oldValue = this.value;
}
});
Expand Down

0 comments on commit fae14aa

Please sign in to comment.