Adds caching components.length in shorthand compactor.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 8 Jun 2014 20:12:19 +0000 (21:12 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 8 Jun 2014 20:34:35 +0000 (21:34 +0100)
lib/properties/shorthand-compactor.js

index 12f7c98..5b539e6 100644 (file)
@@ -61,6 +61,7 @@ module.exports = (function () {
     // Tries to compact a prop in componentsSoFar
     var compactSoFar = function (prop) {
       var i;
+      var componentsCount = processable[prop].components.length;
 
       // Check basics
       if (!componentsSoFar[prop] || !componentsSoFar[prop].found)
@@ -69,7 +70,7 @@ module.exports = (function () {
       // Find components for the shorthand
       var components = [];
       var realComponents = [];
-      for (i = 0; i < processable[prop].components.length; i++) {
+      for (i = 0 ; i < componentsCount; i++) {
         // Get property name
         var pp = processable[prop].components[i];
 
@@ -95,7 +96,7 @@ module.exports = (function () {
         return false;
       }
 
-      if (realComponents.length === processable[prop].components.length) {
+      if (realComponents.length === componentsCount) {
         // When all the components are from real values, only allow shorthanding if their understandability allows it
         // This is the case when every component can override their default values, or when all of them use the same function
 
@@ -132,7 +133,7 @@ module.exports = (function () {
       var compactedLength = Token.getDetokenizedLength(compacted);
       var authenticLength = Token.getDetokenizedLength(realComponents);
 
-      if (realComponents.length === processable[prop].components.length || compactedLength < authenticLength || components.some(isHackValue)) {
+      if (realComponents.length === componentsCount || compactedLength < authenticLength || components.some(isHackValue)) {
         compacted[0].isShorthand = true;
         compacted[0].components = processable[prop].breakUp(compacted[0]);