Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change the Length class's caching of parsed units and number values s…

…o it spans across instances rather than just being for the current instance.
  • Loading branch information...
commit cff46c3677c933bc34c640858e7d9e23ffbafb68 1 parent ff6d750
Jason Johnston authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 sources/Length.js
View
15 sources/Length.js
@@ -7,7 +7,9 @@
PIE.Length = (function() {
var lengthCalcEl = doc.createElement( 'length-calc' ),
- s = lengthCalcEl.style;
+ s = lengthCalcEl.style,
+ numCache = {},
+ unitCache = {};
s.position = 'absolute';
s.top = s.left = -9999;
@@ -28,9 +30,10 @@ PIE.Length = (function() {
* @return {number} The value
*/
getNumber: function() {
- var num = this._number;
- if( num === undefined ) {
- num = this._number = parseFloat( this.val );
+ var num = numCache[ this.val ],
+ UNDEF;
+ if( num === UNDEF ) {
+ num = numCache[ this.val ] = parseFloat( this.val );
}
return num;
},
@@ -40,10 +43,10 @@ PIE.Length = (function() {
* @return {string} The unit
*/
getUnit: function() {
- var unit = this._unit, m;
+ var unit = unitCache[ this.val ], m;
if( !unit ) {
m = this.val.match( this.unitRE );
- unit = this._unit = ( m && m[0] ) || 'px';
+ unit = unitCache[ this.val ] = ( m && m[0] ) || 'px';
}
return unit;
},
Please sign in to comment.
Something went wrong with that request. Please try again.