Optimize C++ compilation time

This commit is contained in:
Wojtek Figat
2021-04-30 16:27:57 +02:00
parent 05ba9b8d45
commit 0e75dba142
222 changed files with 1095 additions and 1506 deletions

View File

@@ -2,7 +2,7 @@
#pragma once
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Memory/Memory.h"
#include "Engine/Core/Collections/HashFunctions.h"
#include "Engine/Core/Collections/Config.h"
@@ -781,7 +781,8 @@ public:
/// Gets the keys collection to the output array (will contain unique items).
/// </summary>
/// <param name="result">The result.</param>
void GetKeys(Array<KeyType>& result) const
template<typename AllocationType>
void GetKeys(Array<KeyType, AllocationType>& result) const
{
for (auto i = Begin(); i.IsNotEnd(); ++i)
result.Add(i->Key);
@@ -791,7 +792,8 @@ public:
/// Gets the values collection to the output array (may contain duplicates).
/// </summary>
/// <param name="result">The result.</param>
void GetValues(Array<ValueType>& result) const
template<typename AllocationType>
void GetValues(Array<ValueType, AllocationType>& result) const
{
for (auto i = Begin(); i.IsNotEnd(); ++i)
result.Add(i->Value);

View File

@@ -3,6 +3,8 @@
#pragma once
#include "Engine/Core/Templates.h"
#include "Engine/Platform/Platform.h"
#include <new>
#include "CrtAllocator.h"
typedef CrtAllocator Allocator;

View File

@@ -3,10 +3,9 @@
#pragma once
#include "Span.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Templates.h"
#include "Engine/Core/Memory/Memory.h"
#include "Engine/Platform/Platform.h"
#include "Engine/Serialization/WriteStream.h"
#include "Engine/Serialization/ReadStream.h"
/// <summary>
/// Universal utility class that can store the chunk of data or just reference to the memory.
@@ -49,7 +48,8 @@ public:
/// Initializes a new instance of the <see cref="DataContainer"/> class.
/// </summary>
/// <param name="data">The data array to link.</param>
DataContainer(const Array<T>& data)
template<typename AllocationType>
DataContainer(const Array<T, AllocationType>& data)
: Base((T*)data.Get(), data.Count())
, _isAllocated(false)
{
@@ -147,7 +147,8 @@ public:
/// Link external data
/// </summary>
/// <param name="data">Data array to link</param>
void Link(const Array<T>& data)
template<typename AllocationType>
void Link(const Array<T, AllocationType>& data)
{
Link(data.Get(), data.Count());
}
@@ -217,7 +218,8 @@ public:
/// Copies the data to a new allocated chunk
/// </summary>
/// <param name="data">Data array to copy</param>
FORCE_INLINE void Copy(const Array<T>& data)
template<typename AllocationType>
FORCE_INLINE void Copy(const Array<T, AllocationType>& data)
{
if (data.HasItems())
Copy(data.Get(), data.Count());
@@ -347,10 +349,9 @@ public:
public:
template<typename ReadStream>
void Read(ReadStream* stream, int32 length)
{
// Note: this may not work for the objects, use with primitive types and structures
ASSERT(stream != nullptr);
Allocate(length);
if (length > 0)
@@ -359,10 +360,9 @@ public:
}
}
template<typename WriteStream>
void Write(WriteStream* stream) const
{
// Note: this may not work for the objects, use with primitive types and structures
ASSERT(stream != nullptr);
if (Base::_length > 0)
{

View File

@@ -6,8 +6,8 @@
#include "Engine/Platform/Platform.h"
#include "Engine/Core/Math/Math.h"
const int32 DateTime::CachedDaysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int32 DateTime::CachedDaysToMonth[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
const int32 CachedDaysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int32 CachedDaysToMonth[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
DateTime::DateTime(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second, int32 millisecond)
{
@@ -25,6 +25,11 @@ DateTime::DateTime(int32 year, int32 month, int32 day, int32 hour, int32 minute,
+ millisecond * Constants::TicksPerMillisecond;
}
DateTime DateTime::GetDate() const
{
return DateTime(Ticks - Ticks % Constants::TicksPerDay);
}
void DateTime::GetDate(int32& year, int32& month, int32& day) const
{
// Based on:
@@ -68,6 +73,11 @@ int32 DateTime::GetDayOfYear() const
return day;
}
int32 DateTime::GetHour() const
{
return static_cast<int32>(Ticks / Constants::TicksPerHour % 24);
}
int32 DateTime::GetHour12() const
{
const int32 hour = GetHour();
@@ -78,6 +88,26 @@ int32 DateTime::GetHour12() const
return hour;
}
double DateTime::GetJulianDay() const
{
return 1721425.5 + static_cast<double>(Ticks) / Constants::TicksPerDay;
}
double DateTime::GetModifiedJulianDay() const
{
return GetJulianDay() - 2400000.5;
}
int32 DateTime::GetMillisecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMillisecond % 1000);
}
int32 DateTime::GetMinute() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMinute % 60);
}
int32 DateTime::GetMonth() const
{
int32 year, month, day;
@@ -85,6 +115,21 @@ int32 DateTime::GetMonth() const
return month;
}
MonthOfYear DateTime::GetMonthOfYear() const
{
return static_cast<MonthOfYear>(GetMonth());
}
int32 DateTime::GetSecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerSecond % 60);
}
TimeSpan DateTime::GetTimeOfDay() const
{
return TimeSpan(Ticks % Constants::TicksPerDay);
}
int32 DateTime::GetYear() const
{
int32 year, month, day;
@@ -92,6 +137,11 @@ int32 DateTime::GetYear() const
return year;
}
int32 DateTime::ToUnixTimestamp() const
{
return static_cast<int32>((Ticks - DateTime(1970, 1, 1).Ticks) / Constants::TicksPerSecond);
}
int32 DateTime::DaysInMonth(int32 year, int32 month)
{
ASSERT_LOW_LAYER((month >= 1) && (month <= 12));
@@ -105,6 +155,16 @@ int32 DateTime::DaysInYear(int32 year)
return IsLeapYear(year) ? 366 : 365;
}
DateTime DateTime::FromJulianDay(double julianDay)
{
return DateTime(static_cast<int64>((julianDay - 1721425.5) * Constants::TicksPerDay));
}
DateTime DateTime::FromUnixTimestamp(int32 unixTime)
{
return DateTime(1970, 1, 1) + TimeSpan(static_cast<int64>(unixTime) * Constants::TicksPerSecond);
}
bool DateTime::IsLeapYear(int32 year)
{
if ((year % 4) == 0)
@@ -114,6 +174,11 @@ bool DateTime::IsLeapYear(int32 year)
return false;
}
DateTime DateTime::MaxValue()
{
return DateTime(3652059 * Constants::TicksPerDay - 1);
}
DateTime DateTime::Now()
{
int32 year, month, day, dayOfWeek, hour, minute, second, millisecond;
@@ -144,3 +209,30 @@ String DateTime::ToFileNameString() const
GetDate(year, month, day);
return String::Format(TEXT("{0}_{1:0>2}_{2:0>2}_{3:0>2}_{4:0>2}_{5:0>2}"), year, month, day, GetHour(), GetMinute(), GetSecond());
}
DateTime DateTime::operator+(const TimeSpan& other) const
{
return DateTime(Ticks + other.Ticks);
}
DateTime& DateTime::operator+=(const TimeSpan& other)
{
Ticks += other.Ticks;
return *this;
}
TimeSpan DateTime::operator-(const DateTime& other) const
{
return TimeSpan(Ticks - other.Ticks);
}
DateTime DateTime::operator-(const TimeSpan& other) const
{
return DateTime(Ticks - other.Ticks);
}
DateTime& DateTime::operator-=(const TimeSpan& other)
{
Ticks -= other.Ticks;
return *this;
}

View File

@@ -3,7 +3,8 @@
#pragma once
#include "BaseTypes.h"
#include "TimeSpan.h"
#include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"
#include "Engine/Core/Enums.h"
/// <summary>
@@ -21,11 +22,6 @@ DECLARE_ENUM_EX_12(MonthOfYear, int32, 1, January, February, March, April, May,
/// </summary>
API_STRUCT(InBuild, Namespace="System") struct FLAXENGINE_API DateTime
{
private:
static const int32 CachedDaysPerMonth[];
static const int32 CachedDaysToMonth[];
public:
/// <summary>
@@ -77,32 +73,11 @@ public:
public:
DateTime operator+(const TimeSpan& other) const
{
return DateTime(Ticks + other.Ticks);
}
DateTime& operator+=(const TimeSpan& other)
{
Ticks += other.Ticks;
return *this;
}
TimeSpan operator-(const DateTime& other) const
{
return TimeSpan(Ticks - other.Ticks);
}
DateTime operator-(const TimeSpan& other) const
{
return DateTime(Ticks - other.Ticks);
}
DateTime& operator-=(const TimeSpan& other)
{
Ticks -= other.Ticks;
return *this;
}
DateTime operator+(const TimeSpan& other) const;
DateTime& operator+=(const TimeSpan& other);
TimeSpan operator-(const DateTime& other) const;
DateTime operator-(const TimeSpan& other) const;
DateTime& operator-=(const TimeSpan& other);
bool operator==(const DateTime& other) const
{
@@ -139,11 +114,7 @@ public:
/// <summary>
/// Gets the date part of this date. The time part is truncated and becomes 00:00:00.000.
/// </summary>
/// <returns>A DateTime object containing the date.</returns>
DateTime GetDate() const
{
return DateTime(Ticks - Ticks % Constants::TicksPerDay);
}
DateTime GetDate() const;
/// <summary>
/// Gets the date components of this date.
@@ -156,106 +127,68 @@ public:
/// <summary>
/// Gets this date's day part (1 to 31).
/// </summary>
/// <returns>The day of the month.</returns>
int32 GetDay() const;
/// <summary>
/// Calculates this date's day of the week (Sunday - Saturday).
/// </summary>
/// <returns>The week day.</returns>
DayOfWeek GetDayOfWeek() const;
/// <summary>
/// Gets this date's day of the year.
/// </summary>
/// <returns>The day of year.</returns>
int32 GetDayOfYear() const;
/// <summary>
/// Gets this date's hour part in 24-hour clock format (0 to 23).
/// </summary>
/// <returns>The hour.</returns>
int32 GetHour() const
{
return static_cast<int32>(Ticks / Constants::TicksPerHour % 24);
}
int32 GetHour() const;
/// <summary>
/// Gets this date's hour part in 12-hour clock format (1 to 12).
/// </summary>
/// <returns>The hour in AM/PM format.</returns>
int32 GetHour12() const;
/// <summary>
/// Gets the Julian Day for this date.
/// </summary>
/// <remarks>
/// The Julian Day is the number of days since the inception of the Julian calendar at noon on Monday, January 1, 4713 B.C.E. The minimum Julian Day that can be represented in DateTime is 1721425.5, which corresponds to Monday, January 1, 0001 in the Gregorian calendar.
/// </remarks>
/// <returns>Julian Day.</returns>
double GetJulianDay() const
{
return 1721425.5 + static_cast<double>(Ticks) / Constants::TicksPerDay;
}
/// <remarks>The Julian Day is the number of days since the inception of the Julian calendar at noon on Monday, January 1, 4713 B.C.E. The minimum Julian Day that can be represented in DateTime is 1721425.5, which corresponds to Monday, January 1, 0001 in the Gregorian calendar.</remarks>
double GetJulianDay() const;
/// <summary>
/// Gets the Modified Julian day.
/// </summary>
/// <remarks>
/// The Modified Julian Day is calculated by subtracting 2400000.5, which corresponds to midnight UTC on November 17, 1858 in the Gregorian calendar.
/// </remarks>
/// <returns>The Modified Julian Day.</returns>
double GetModifiedJulianDay() const
{
return GetJulianDay() - 2400000.5;
}
/// <remarks>The Modified Julian Day is calculated by subtracting 2400000.5, which corresponds to midnight UTC on November 17, 1858 in the Gregorian calendar.</remarks>
double GetModifiedJulianDay() const;
/// <summary>
/// Gets this date's millisecond part (0 to 999).
/// </summary>
/// <returns>The millisecond.</returns>
int32 GetMillisecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMillisecond % 1000);
}
int32 GetMillisecond() const;
/// <summary>
/// Gets this date's minute part (0 to 59).
/// </summary>
/// <returns>The minute.</returns>
int32 GetMinute() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMinute % 60);
}
int32 GetMinute() const;
/// <summary>
/// Gets this date's the month part (1 to 12).
/// </summary>
/// <returns>The month.</returns>
int32 GetMonth() const;
/// <summary>
/// Gets the date's month of the year (January to December).
/// </summary>
/// <returns>The month of year.</returns>
MonthOfYear GetMonthOfYear() const
{
return static_cast<MonthOfYear>(GetMonth());
}
MonthOfYear GetMonthOfYear() const;
/// <summary>
/// Gets this date's second part.
/// </summary>
/// <returns>The second.</returns>
int32 GetSecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerSecond % 60);
}
int32 GetSecond() const;
/// <summary>
/// Gets this date's representation as number of ticks.
/// Gets this date's representation as number of ticks since midnight, January 1, 0001.
/// </summary>
/// <returns>The number of ticks since midnight, January 1, 0001.</returns>
int64 GetTicks() const
{
return Ticks;
@@ -264,26 +197,17 @@ public:
/// <summary>
/// Gets the time elapsed since midnight of this date.
/// </summary>
/// <returns>The time span since midnight.</returns>
TimeSpan GetTimeOfDay() const
{
return TimeSpan(Ticks % Constants::TicksPerDay);
}
TimeSpan GetTimeOfDay() const;
/// <summary>
/// Gets this date's year part.
/// </summary>
/// <returns>The year.</returns>
int32 GetYear() const;
/// <summary>
/// Gets this date as the number of seconds since the Unix Epoch (January 1st of 1970).
/// </summary>
/// <returns>The time.</returns>
int32 ToUnixTimestamp() const
{
return static_cast<int32>((Ticks - DateTime(1970, 1, 1).Ticks) / Constants::TicksPerSecond);
}
int32 ToUnixTimestamp() const;
public:
@@ -307,27 +231,19 @@ public:
/// </summary>
/// <param name="julianDay">The Julian Day.</param>
/// <returns>Gregorian date and time.</returns>
static DateTime FromJulianDay(double julianDay)
{
return DateTime(static_cast<int64>((julianDay - 1721425.5) * Constants::TicksPerDay));
}
static DateTime FromJulianDay(double julianDay);
/// <summary>
/// Returns the date from Unix time (seconds from midnight 1970-01-01).
/// </summary>
/// <param name="unixTime">The Unix time (seconds from midnight 1970-01-01).</param>
/// <returns>The Gregorian date and time.</returns>
static DateTime FromUnixTimestamp(int32 unixTime)
{
return DateTime(1970, 1, 1) + TimeSpan(static_cast<int64>(unixTime) * Constants::TicksPerSecond);
}
static DateTime FromUnixTimestamp(int32 unixTime);
/// <summary>
/// Determines whether the specified year is a leap year.
/// </summary>
/// <remarks>
/// A leap year is a year containing one additional day in order to keep the calendar synchronized with the astronomical year.
/// </remarks>
/// <remarks>A leap year is a year containing one additional day in order to keep the calendar synchronized with the astronomical year.</remarks>
/// <param name="year">The year.</param>
/// <returns><c>true</c> if the specified year os a leap year; otherwise, <c>false</c>.</returns>
static bool IsLeapYear(int32 year);
@@ -335,22 +251,15 @@ public:
/// <summary>
/// Returns the maximum date value.
/// </summary>
/// <remarks>
/// The maximum date value is December 31, 9999, 23:59:59.9999999.
/// </remarks>
/// <returns>The date.</returns>
static DateTime MaxValue()
{
return DateTime(3652059 * Constants::TicksPerDay - 1);
}
/// <remarks>The maximum date value is December 31, 9999, 23:59:59.9999999.</remarks>
/// <returns>The maximum valid date.</returns>
static DateTime MaxValue();
/// <summary>
/// Returns the minimum date value.
/// </summary>
/// <remarks>
/// The minimum date value is January 1, 0001, 00:00:00.0.
/// </remarks>
/// <returns>The date.</returns>
/// <remarks>The minimum date value is January 1, 0001, 00:00:00.0.</remarks>
/// <returns>The minimum valid date.</returns>
static DateTime MinValue()
{
return DateTime(1, 1, 1, 0, 0, 0, 0);
@@ -359,18 +268,14 @@ public:
/// <summary>
/// Gets the local date and time on this computer.
/// </summary>
/// <remarks>
///This method takes into account the local computer's time zone and daylight saving settings. For time zone independent time comparisons, and when comparing times between different computers, use NowUTC() instead.
/// </remarks>
/// <remarks>This method takes into account the local computer's time zone and daylight saving settings. For time zone independent time comparisons, and when comparing times between different computers, use NowUTC() instead.</remarks>
/// <returns>The current date and time.</returns>
static DateTime Now();
/// <summary>
/// Gets the UTC date and time on this computer.
/// </summary>
/// <remarks>
/// This method returns the Coordinated Universal Time (UTC), which does not take the local computer's time zone and daylight savings settings into account. It should be used when comparing dates and times that should be independent of the user's locale. To get the date and time in the current locale, use Now() instead.
/// </remarks>
/// <remarks>This method returns the Coordinated Universal Time (UTC), which does not take the local computer's time zone and daylight savings settings into account. It should be used when comparing dates and times that should be independent of the user's locale. To get the date and time in the current locale, use Now() instead.</remarks>
/// <returns>The current date and time.</returns>
static DateTime NowUTC();

View File

@@ -5,6 +5,7 @@
#include "Engine/Platform/Platform.h"
#include "Engine/Platform/StringUtils.h"
#include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"
/// <summary>
/// Represents text as a sequence of characters. Container uses a single dynamic memory allocation to store the characters data. Characters sequence is always null-terminated.

View File

@@ -66,7 +66,6 @@ public:
/// <summary>
/// Returns true if string is empty.
/// </summary>
/// <returns>True if string is empty, otherwise false.</returns>
FORCE_INLINE bool IsEmpty() const
{
return _length == 0;
@@ -75,7 +74,6 @@ public:
/// <summary>
/// Returns true if string isn't empty.
/// </summary>
/// <returns>True if string isn't empty, otherwise false.</returns>
FORCE_INLINE bool HasChars() const
{
return _length != 0;
@@ -84,7 +82,6 @@ public:
/// <summary>
/// Gets the length of the string.
/// </summary>
/// <returns>The string length.</returns>
FORCE_INLINE int32 Length() const
{
return _length;
@@ -93,7 +90,6 @@ public:
/// <summary>
/// Gets the pointer to the string.
/// </summary>
/// <returns>The string.</returns>
FORCE_INLINE const T* operator*() const
{
return _data;
@@ -102,7 +98,6 @@ public:
/// <summary>
/// Gets the pointer to the string.
/// </summary>
/// <returns>The string.</returns>
FORCE_INLINE const T* Get() const
{
return _data;
@@ -111,7 +106,6 @@ public:
/// <summary>
/// Gets the pointer to the string or to the static empty text if string is null. Returned pointer is always valid (read-only).
/// </summary>
/// <returns>The string handle.</returns>
FORCE_INLINE const T* GetText() const
{
return _data ? _data : (const T*)TEXT("");

View File

@@ -3,7 +3,6 @@
#pragma once
#include "BaseTypes.h"
#include "Engine/Platform/Platform.h"
#include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"