Small optimization

This commit is contained in:
NeeEoo
2024-04-17 19:46:10 +02:00
parent 65e8b9b4e2
commit f081470554
2 changed files with 7 additions and 8 deletions
@@ -17,7 +17,7 @@ class SystemInfo extends FramerateCategory {
static var __formattedSysText:String = "";
public static inline function init() {
public static function init() {
#if linux
var process = new HiddenProcess("cat", ["/etc/os-release"]);
if (process.exitCode() != 0) Logs.trace('Unable to grab OS Label', ERROR, RED);
+6 -7
View File
@@ -133,10 +133,8 @@ class CoolUtil
* Whenever a value is NaN or not.
* @param v Value
*/
public static inline function isNaN(v:Dynamic) {
if (v is Float || v is Int)
return Math.isNaN(cast(v, Float));
return false;
public static inline function isNaN(v:Dynamic):Bool {
return (v is Float) ? Math.isNaN(cast(v, Float)) : false;
}
/**
@@ -185,20 +183,21 @@ class CoolUtil
return str;
}
private static var sizeLabels:Array<String> = ["B", "KB", "MB", "GB", "TB"];
/**
* Returns a string representation of a size, following this format: `1.02 GB`, `134.00 MB`
* @param size Size to convert to string
* @return String Result string representation
*/
public static function getSizeString(size:Float):String {
var labels = ["B", "KB", "MB", "GB", "TB"];
var rSize:Float = size;
var label:Int = 0;
while(rSize > 1024 && label < labels.length-1) {
while(rSize > 1024 && label < sizeLabels.length-1) {
label++;
rSize /= 1024;
}
return '${Std.int(rSize) + "." + addZeros(Std.string(Std.int((rSize % 1) * 100)), 2)}${labels[label]}';
return Std.int(rSize) + "." + addZeros(Std.string(Std.int((rSize % 1) * 100)), 2) + sizeLabels[label];
}
/**