Improve #1120 to use shared lookup table export from engine source and reduce memory alloc from Array via Span
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
#include "ObjectsRemovalService.h"
|
#include "ObjectsRemovalService.h"
|
||||||
|
#include "Utilities.h"
|
||||||
#include "Collections/Dictionary.h"
|
#include "Collections/Dictionary.h"
|
||||||
#include "Engine/Engine/Time.h"
|
#include "Engine/Engine/Time.h"
|
||||||
#include "Engine/Engine/EngineService.h"
|
#include "Engine/Engine/EngineService.h"
|
||||||
@@ -8,6 +9,11 @@
|
|||||||
#include "Engine/Profiler/ProfilerCPU.h"
|
#include "Engine/Profiler/ProfilerCPU.h"
|
||||||
#include "Engine/Scripting/ScriptingObject.h"
|
#include "Engine/Scripting/ScriptingObject.h"
|
||||||
|
|
||||||
|
const Char* BytesSizesData[] = { TEXT("b"), TEXT("Kb"), TEXT("Mb"), TEXT("Gb"), TEXT("Tb"), TEXT("Pb"), TEXT("Eb"), TEXT("Zb"), TEXT("Yb") };
|
||||||
|
const Char* HertzSizesData[] = { TEXT("Hz"), TEXT("KHz"), TEXT("MHz"), TEXT("GHz"), TEXT("THz"), TEXT("PHz"), TEXT("EHz"), TEXT("ZHz"), TEXT("YHz") };
|
||||||
|
Span<const Char*> Utilities::Private::BytesSizes(BytesSizesData, ARRAY_COUNT(BytesSizesData));
|
||||||
|
Span<const Char*> Utilities::Private::HertzSizes(HertzSizesData, ARRAY_COUNT(HertzSizesData));
|
||||||
|
|
||||||
namespace ObjectsRemovalServiceImpl
|
namespace ObjectsRemovalServiceImpl
|
||||||
{
|
{
|
||||||
CriticalSection PoolLocker;
|
CriticalSection PoolLocker;
|
||||||
|
|||||||
@@ -4,12 +4,19 @@
|
|||||||
|
|
||||||
#include "Types/BaseTypes.h"
|
#include "Types/BaseTypes.h"
|
||||||
#include "Types/String.h"
|
#include "Types/String.h"
|
||||||
|
#include "Types/Span.h"
|
||||||
#if _MSC_VER && PLATFORM_SIMD_SSE4_2
|
#if _MSC_VER && PLATFORM_SIMD_SSE4_2
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Utilities
|
namespace Utilities
|
||||||
{
|
{
|
||||||
|
struct Private
|
||||||
|
{
|
||||||
|
static FLAXENGINE_API Span<const Char*> BytesSizes;
|
||||||
|
static FLAXENGINE_API Span<const Char*> HertzSizes;
|
||||||
|
};
|
||||||
|
|
||||||
// Round floating point value up to 1 decimal place
|
// Round floating point value up to 1 decimal place
|
||||||
template<typename T>
|
template<typename T>
|
||||||
FORCE_INLINE T RoundTo1DecimalPlace(T value)
|
FORCE_INLINE T RoundTo1DecimalPlace(T value)
|
||||||
@@ -37,17 +44,17 @@ namespace Utilities
|
|||||||
// @param sizes Array with human-readable sizes to convert from
|
// @param sizes Array with human-readable sizes to convert from
|
||||||
// @return The best fitting string of the units
|
// @return The best fitting string of the units
|
||||||
template<typename T>
|
template<typename T>
|
||||||
String UnitsToText(T units, int32 divider, const Array<String>& sizes)
|
String UnitsToText(T units, int32 divider, const Span<const Char*> sizes)
|
||||||
{
|
{
|
||||||
if(sizes.Count() == 0)
|
if (sizes.Length() == 0)
|
||||||
return String::Format(TEXT("{0}"), units);
|
return String::Format(TEXT("{0}"), units);
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
double dblSUnits = static_cast<double>(units);
|
double dblSUnits = static_cast<double>(units);
|
||||||
for (; static_cast<uint64>(units / static_cast<double>(divider)) > 0; i++, units /= divider)
|
for (; static_cast<uint64>(units / static_cast<double>(divider)) > 0; i++, units /= divider)
|
||||||
dblSUnits = units / static_cast<double>(divider);
|
dblSUnits = units / static_cast<double>(divider);
|
||||||
if (i >= sizes.Count())
|
if (i >= sizes.Length())
|
||||||
return String::Format(TEXT("{0}{1}"), units, sizes[0]);
|
i = 0;
|
||||||
return String::Format(TEXT("{0}{1}"), RoundTo2DecimalPlaces(dblSUnits), sizes[i]);
|
return String::Format(TEXT("{0} {1}"), RoundTo2DecimalPlaces(dblSUnits), sizes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts size of the file (in bytes) to the best fitting string
|
// Converts size of the file (in bytes) to the best fitting string
|
||||||
@@ -56,8 +63,7 @@ namespace Utilities
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
String BytesToText(T bytes)
|
String BytesToText(T bytes)
|
||||||
{
|
{
|
||||||
static Array<String> sizes = { TEXT("b"), TEXT("Kb"), TEXT("Mb"), TEXT("Gb"), TEXT("Tb"), TEXT("Pb"), TEXT("Eb"), TEXT("Zb"), TEXT("Yb") };
|
return UnitsToText(bytes, 1024, Private::BytesSizes);
|
||||||
return UnitsToText(bytes, 1024, sizes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts hertz to the best fitting string
|
// Converts hertz to the best fitting string
|
||||||
@@ -66,8 +72,7 @@ namespace Utilities
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
String HertzToText(T hertz)
|
String HertzToText(T hertz)
|
||||||
{
|
{
|
||||||
static Array<String> sizes = { TEXT("Hz"), TEXT("KHz"), TEXT("MHz"), TEXT("GHz"), TEXT("THz"), TEXT("PHz"), TEXT("EHz"), TEXT("ZHz"), TEXT("YHz") };
|
return UnitsToText(hertz, 1000, Private::HertzSizes);
|
||||||
return UnitsToText(hertz, 1000, sizes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the amount of set bits in 32-bit integer.
|
// Returns the amount of set bits in 32-bit integer.
|
||||||
|
|||||||
Reference in New Issue
Block a user