Skip to content

Commit

Permalink
Use flattened list of properties for fast access during configuration…
Browse files Browse the repository at this point in the history
… and attribute->property
  • Loading branch information
Steven Orvell committed Oct 20, 2015
1 parent 4745e8f commit acdd242
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
2 changes: 2 additions & 0 deletions polymer-micro.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
this._prepBehaviors();
// factory
this._prepConstructor();
// fast access to property info
this._prepPropertyInfo();
},

_prepBehavior: function(b) {
Expand Down
2 changes: 2 additions & 0 deletions polymer-mini.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
this._prepTemplate();
// dom encapsulation
this._prepShady();
// fast access to property info
this._prepPropertyInfo();
},

_prepBehavior: function(b) {
Expand Down
2 changes: 2 additions & 0 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
this._prepBindings();
// dom encapsulation
this._prepShady();
// fast access to property info
this._prepPropertyInfo();
},

_prepBehavior: function(b) {
Expand Down
25 changes: 16 additions & 9 deletions src/micro/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,27 @@
},

_takeAttributesToModel: function(model) {
for (var i=0, l=this.attributes.length; i<l; i++) {
this._setAttributeToProperty(model, this.attributes[i].name);
for (var i in this._propertyInfo) {
var info = this._propertyInfo[i];
if (this.hasAttribute(info.attribute)) {
this._setAttributeToProperty(model, info.attribute, i, info);
}
}
},

_setAttributeToProperty: function(model, attrName) {
_setAttributeToProperty: function(model, attribute, property, info) {
// Don't deserialize back to property if currently reflecting
if (!this._serializing) {
var propName = Polymer.CaseMap.dashToCamelCase(attrName);
var info = this.getPropertyInfo(propName);
if (info.defined ||
(this._propertyEffects && this._propertyEffects[propName])) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, info.type);
var property = property || Polymer.CaseMap.dashToCamelCase(attribute);
// fallback to property lookup
info = info || this._propertyInfo[property];
if (info && !info.readOnly) {
var v = this.getAttribute(attribute);
// TODO(sorvell): maybe not kosher but under current rules,
// we can avoid deserializing null values for non-Boolean types.
if (v !== null || info.type === Boolean) {
model[property] = this.deserialize(v, info.type);
}
}
}
},
Expand Down
34 changes: 33 additions & 1 deletion src/micro/properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,39 @@
p.defined = true;
}
return p;
}
},

// union properties, behaviors.properties, and propertyEffects
_prepPropertyInfo: function() {
this._propertyInfo = {};
for (var i=0, p; i < this.behaviors.length; i++) {
this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties);
}
this._addPropertyInfo(this._propertyInfo, this.properties);
this._addPropertyInfo(this._propertyInfo, this._propertyEffects);
},

// list of propertyInfo with {readOnly, type, attribute}
_addPropertyInfo: function(target, source) {
if (source) {
var t, s;
for (var i in source) {
t = target[i];
s = source[i];
if (!target[i]) {
target[i] = t = typeof(s) === 'function' ? {type: s} : s;
t.attribute = Polymer.CaseMap.camelToDashCase(i);
} else {
if (!t.type) {
t.type = s.type;
}
if (!t.readOnly) {
t.readOnly = s.readOnly;
}
}
}
}
},

});

Expand Down
10 changes: 9 additions & 1 deletion src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
}
// prototypical behavior
this._configureProperties(this.properties, config);
// TODO(sorvell): it *may* be faster to loop over _propertyInfo but
// there are some test issues.
//this._configureProperties(this._propertyInfo, config);
// override local configuration with configuration from above
this._mixinConfigure(config, this._aboveConfig);
// this is the new _config, which are the final values to be applied
Expand All @@ -119,7 +122,12 @@

_mixinConfigure: function(a, b) {
for (var prop in b) {
if (!this.getPropertyInfo(prop).readOnly) {
//if (!this.getPropertyInfo(prop).readOnly) {
// TODO(sorvell): tempatized things don't have _propertyInfo atm
// so fallback to property lookup.
var info = this._propertyInfo && this._propertyInfo[prop] ||
this.getPropertyInfo(prop);
if (!info.readOnly) {
a[prop] = b[prop];
}
}
Expand Down

0 comments on commit acdd242

Please sign in to comment.