Skip to content

Commit acdd242

Browse files
author
Steven Orvell
committed
Use flattened list of properties for fast access during configuration and attribute->property
1 parent 4745e8f commit acdd242

6 files changed

Lines changed: 64 additions & 11 deletions

File tree

‎polymer-micro.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
this._prepBehaviors();
3434
// factory
3535
this._prepConstructor();
36+
// fast access to property info
37+
this._prepPropertyInfo();
3638
},
3739

3840
_prepBehavior: function(b) {

‎polymer-mini.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
this._prepTemplate();
3535
// dom encapsulation
3636
this._prepShady();
37+
// fast access to property info
38+
this._prepPropertyInfo();
3739
},
3840

3941
_prepBehavior: function(b) {

‎polymer.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
this._prepBindings();
4949
// dom encapsulation
5050
this._prepShady();
51+
// fast access to property info
52+
this._prepPropertyInfo();
5153
},
5254

5355
_prepBehavior: function(b) {

‎src/micro/attributes.html‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,27 @@
9191
},
9292

9393
_takeAttributesToModel: function(model) {
94-
for (var i=0, l=this.attributes.length; i<l; i++) {
95-
this._setAttributeToProperty(model, this.attributes[i].name);
94+
for (var i in this._propertyInfo) {
95+
var info = this._propertyInfo[i];
96+
if (this.hasAttribute(info.attribute)) {
97+
this._setAttributeToProperty(model, info.attribute, i, info);
98+
}
9699
}
97100
},
98101

99-
_setAttributeToProperty: function(model, attrName) {
102+
_setAttributeToProperty: function(model, attribute, property, info) {
100103
// Don't deserialize back to property if currently reflecting
101104
if (!this._serializing) {
102-
var propName = Polymer.CaseMap.dashToCamelCase(attrName);
103-
var info = this.getPropertyInfo(propName);
104-
if (info.defined ||
105-
(this._propertyEffects && this._propertyEffects[propName])) {
106-
var val = this.getAttribute(attrName);
107-
model[propName] = this.deserialize(val, info.type);
105+
var property = property || Polymer.CaseMap.dashToCamelCase(attribute);
106+
// fallback to property lookup
107+
info = info || this._propertyInfo[property];
108+
if (info && !info.readOnly) {
109+
var v = this.getAttribute(attribute);
110+
// TODO(sorvell): maybe not kosher but under current rules,
111+
// we can avoid deserializing null values for non-Boolean types.
112+
if (v !== null || info.type === Boolean) {
113+
model[property] = this.deserialize(v, info.type);
114+
}
108115
}
109116
}
110117
},

‎src/micro/properties.html‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,39 @@
127127
p.defined = true;
128128
}
129129
return p;
130-
}
130+
},
131+
132+
// union properties, behaviors.properties, and propertyEffects
133+
_prepPropertyInfo: function() {
134+
this._propertyInfo = {};
135+
for (var i=0, p; i < this.behaviors.length; i++) {
136+
this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties);
137+
}
138+
this._addPropertyInfo(this._propertyInfo, this.properties);
139+
this._addPropertyInfo(this._propertyInfo, this._propertyEffects);
140+
},
141+
142+
// list of propertyInfo with {readOnly, type, attribute}
143+
_addPropertyInfo: function(target, source) {
144+
if (source) {
145+
var t, s;
146+
for (var i in source) {
147+
t = target[i];
148+
s = source[i];
149+
if (!target[i]) {
150+
target[i] = t = typeof(s) === 'function' ? {type: s} : s;
151+
t.attribute = Polymer.CaseMap.camelToDashCase(i);
152+
} else {
153+
if (!t.type) {
154+
t.type = s.type;
155+
}
156+
if (!t.readOnly) {
157+
t.readOnly = s.readOnly;
158+
}
159+
}
160+
}
161+
}
162+
},
131163

132164
});
133165

‎src/standard/configure.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
}
9595
// prototypical behavior
9696
this._configureProperties(this.properties, config);
97+
// TODO(sorvell): it *may* be faster to loop over _propertyInfo but
98+
// there are some test issues.
99+
//this._configureProperties(this._propertyInfo, config);
97100
// override local configuration with configuration from above
98101
this._mixinConfigure(config, this._aboveConfig);
99102
// this is the new _config, which are the final values to be applied
@@ -119,7 +122,12 @@
119122

120123
_mixinConfigure: function(a, b) {
121124
for (var prop in b) {
122-
if (!this.getPropertyInfo(prop).readOnly) {
125+
//if (!this.getPropertyInfo(prop).readOnly) {
126+
// TODO(sorvell): tempatized things don't have _propertyInfo atm
127+
// so fallback to property lookup.
128+
var info = this._propertyInfo && this._propertyInfo[prop] ||
129+
this.getPropertyInfo(prop);
130+
if (!info.readOnly) {
123131
a[prop] = b[prop];
124132
}
125133
}

0 commit comments

Comments
 (0)