Optimize Stream includes to Array

This commit is contained in:
Wojtek Figat
2022-01-02 01:28:06 +01:00
parent 68d8766c56
commit 32a73727b0
6 changed files with 18 additions and 13 deletions

View File

@@ -3,6 +3,7 @@
#pragma once
#include "ReadStream.h"
#include "Engine/Platform/Platform.h"
/// <summary>
/// Super fast advanced data reading from raw bytes without any overhead at all
@@ -33,8 +34,8 @@ public:
/// Init
/// </summary>
/// <param name="data">Array with data to read from</param>
template<typename T>
MemoryReadStream(const Array<T>& data)
template<typename T, typename AllocationType = HeapAllocation>
MemoryReadStream(const Array<T, AllocationType>& data)
: MemoryReadStream(data.Get(), data.Count() * sizeof(T))
{
}
@@ -52,8 +53,8 @@ public:
/// Init stream to the custom buffer location
/// </summary>
/// <param name="data">Array with data to read from</param>
template<typename T>
FORCE_INLINE void Init(const Array<T>& data)
template<typename T, typename AllocationType = HeapAllocation>
FORCE_INLINE void Init(const Array<T, AllocationType>& data)
{
Init(data.Get(), data.Count() * sizeof(T));
}

View File

@@ -2,8 +2,8 @@
#pragma once
#include "Engine/Core/Collections/Array.h"
#include "Stream.h"
#include "Engine/Core/Templates.h"
struct CommonValue;
struct Variant;
@@ -193,9 +193,10 @@ public:
/// Read data array
/// </summary>
/// <param name="data">Array to read</param>
template<typename T>
void ReadArray(Array<T>* data)
template<typename T, typename AllocationType = HeapAllocation>
void ReadArray(Array<T, AllocationType>* data)
{
static_assert(TIsPODType<T>::Value, "Only POD types are valid for ReadArray.");
int32 size;
ReadInt32(&size);
data->Resize(size, false);

View File

@@ -519,7 +519,7 @@ void WriteStream::WriteStringAnsi(const StringAnsiView& data)
Write(data.Get(), length);
}
void WriteStream::WriteStringAnsi(const StringAnsiView& data, int16 lock)
void WriteStream::WriteStringAnsi(const StringAnsiView& data, int8 lock)
{
const int32 length = data.Length();
ASSERT(length < STREAM_MAX_STRING_LENGTH);

View File

@@ -2,6 +2,7 @@
#pragma once
#include "Engine/Core/Core.h"
#include "Engine/Core/Types/BaseTypes.h"
#define FILESTREAM_BUFFER_SIZE 4096

View File

@@ -2,9 +2,8 @@
#pragma once
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Formatting.h"
#include "Stream.h"
#include "Engine/Core/Templates.h"
struct CommonValue;
struct Variant;
@@ -211,7 +210,7 @@ public:
// Writes Ansi String to the stream
// @param data Data to write
// @param lock Characters pass in the stream
void WriteStringAnsi(const StringAnsiView& data, int16 lock);
void WriteStringAnsi(const StringAnsiView& data, int8 lock);
public:
@@ -231,8 +230,8 @@ public:
/// Write data array
/// </summary>
/// <param name="data">Array to write</param>
template<typename T>
void WriteArray(const Array<T>& data)
template<typename T, typename AllocationType = HeapAllocation>
void WriteArray(const Array<T, AllocationType>& data)
{
static_assert(TIsPODType<T>::Value, "Only POD types are valid for WriteArray.");
const int32 size = data.Count();