Explorar o código

Check if array is iterable without full key diff.

~0.5-1% performance gain.
Justin Hileman %!s(int64=13) %!d(string=hai) anos
pai
achega
e09bfb502f
Modificáronse 1 ficheiros con 10 adicións e 3 borrados
  1. 10 3
      src/Mustache/Context.php

+ 10 - 3
src/Mustache/Context.php

@@ -61,10 +61,17 @@ class Context {
 		if (is_object($value)) {
 			return $value instanceof \Traversable;
 		} elseif (is_array($value)) {
-			return !array_diff_key($value, array_keys(array_keys($value)));
-		}
+			$i = 0;
+			foreach ($value as $k => $v) {
+				if ($k !== $i++) {
+					return false;
+				}
+			}
 
-		return false;
+			return true;
+		} else {
+			return false;
+		}
 	}
 
 	/**