Przeglądaj źródła

Check if array is iterable without full key diff.

~0.5-1% performance gain.
Justin Hileman 13 lat temu
rodzic
commit
e09bfb502f
1 zmienionych plików z 10 dodań i 3 usunięć
  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;
+		}
 	}
 
 	/**