Skip to content
This repository
Browse code

opmitisation of fromReadableSize

  • Loading branch information...
commit 90c32add9cea115ca7c6ffc4acc6f792565898a3 1 parent 07c5102
ceeram authored September 18, 2012

Showing 1 changed file with 6 additions and 5 deletions. Show diff stats Hide diff stats

  1. 11  lib/Cake/Utility/CakeNumber.php
11  lib/Cake/Utility/CakeNumber.php
@@ -112,15 +112,16 @@ public static function fromReadableSize($size, $default = false) {
112 112
 		if (ctype_digit($size)) {
113 113
 			return $size * 1;
114 114
 		}
115  
-		$units = array('KB', 'MB', 'GB', 'TB', 'PB');
116  
-		foreach ($units as $i => $unit) {
117  
-			if ($unit == substr($size, -2)) {
118  
-				return $size * pow(1024, $i + 1);
119  
-			}
  115
+
  116
+		$i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB'));
  117
+		if ($i !== false) {
  118
+			return $size * pow(1024, $i + 1);
120 119
 		}
  120
+
121 121
 		if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) {
122 122
 			return $size * 1;
123 123
 		}
  124
+
124 125
 		if ($default !== false) {
125 126
 			return $default;
126 127
 		}

0 notes on commit 90c32ad

Please sign in to comment.
Something went wrong with that request. Please try again.