Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cache the parsed CSS object structures for each unique CSS value stri…

…ng. This gives a decent performance boost when the same styles are used on several elements.
  • Loading branch information...
commit 6b374bb3f8dd08cc9eb419708cb2bd50979fd09a 1 parent 88e7e45
Jason Johnston authored
Showing with 7 additions and 7 deletions.
  1. +7 −7 sources/StyleInfoBase.js
View
14 sources/StyleInfoBase.js
@@ -10,19 +10,19 @@ PIE.StyleInfoBase = {
this.element = el;
}
PIE.Util.merge( StyleInfo.prototype, PIE.StyleInfoBase, proto );
+ StyleInfo._propsCache = {};
return StyleInfo;
},
/**
- * Get an object representation of the target CSS style, caching it as long as the
- * underlying CSS value hasn't changed.
+ * Get an object representation of the target CSS style, caching it for each unique
+ * CSS value string.
* @return {Object}
*/
getProps: function() {
- if( this.changed() ) {
- this._props = this.parseCss( this._css = this.getCss() );
- }
- return this._props;
+ var css = this._lastCss = this.getCss(),
+ cache = this.constructor._propsCache;
+ return css ? ( css in cache ? cache[ css ] : ( cache[ css ] = this.parseCss( css ) ) ) : null;
},
/**
@@ -53,6 +53,6 @@ PIE.StyleInfoBase = {
* @return {boolean}
*/
changed: function() {
- return this._css !== this.getCss();
+ return this._lastCss !== this.getCss();
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.