Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

opmitisation of fromReadableSize

  • Loading branch information...
commit 90c32add9cea115ca7c6ffc4acc6f792565898a3 1 parent 07c5102
@ceeram ceeram authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/Cake/Utility/CakeNumber.php
View
11 lib/Cake/Utility/CakeNumber.php
@@ -112,15 +112,16 @@ public static function fromReadableSize($size, $default = false) {
if (ctype_digit($size)) {
return $size * 1;
}
- $units = array('KB', 'MB', 'GB', 'TB', 'PB');
- foreach ($units as $i => $unit) {
- if ($unit == substr($size, -2)) {
- return $size * pow(1024, $i + 1);
- }
+
+ $i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB'));
+ if ($i !== false) {
+ return $size * pow(1024, $i + 1);
}
+
if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) {
return $size * 1;
}
+
if ($default !== false) {
return $default;
}
Please sign in to comment.
Something went wrong with that request. Please try again.