Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
MemoryStream::Chunk Struct Referencefinal
Collaboration diagram for MemoryStream::Chunk:
[legend]

Public Member Functions

size_t Append (StreamChunk &dataView)
 

Public Attributes

std::array< uint8_t, ChunkSizeData
 
size_t BytesUsed { 0 }
 

Detailed Description

Definition at line 42 of file lib-utility/memorystream.h.

Member Function Documentation

◆ Append()

size_t MemoryStream::Chunk::Append ( StreamChunk dataView)

Definition at line 67 of file lib-utility/memorystream.cpp.

68{
69 const size_t dataSize = dataView.second;
70
71 const size_t bytesToWrite = std::min(ChunkSize - BytesUsed, dataSize);
72 const size_t bytesLeft = dataSize - bytesToWrite;
73
74 const uint8_t* beginData = static_cast<const uint8_t*>(dataView.first);
75 const uint8_t* endData = beginData + bytesToWrite;
76
77 // Some extreme micro optimization for MSVC (at least)
78 // std::copy will generate a call to memmove in any case
79 // which will be slower than just writing the byte
80 if (bytesToWrite == 1)
81 {
82 Data[BytesUsed] = *beginData;
83 }
84 else
85 {
86 // There is a chance for unaligned access, so we do no handle
87 // types as int32_t separately. Unaligned access is slow on x86
88 // and fails horribly on ARM
89 std::copy(beginData, endData, Data.begin() + BytesUsed);
90 }
91
92 dataView.first = endData;
93 dataView.second = bytesLeft;
94
95 BytesUsed += bytesToWrite;
96
97 return bytesLeft;
98}
int min(int a, int b)
static constexpr size_t ChunkSize
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40
std::array< uint8_t, ChunkSize > Data

References BytesUsed, MemoryStream::ChunkSize, staffpad::vo::copy(), Data, and min().

Here is the call graph for this function:

Member Data Documentation

◆ BytesUsed

size_t MemoryStream::Chunk::BytesUsed { 0 }

Definition at line 45 of file lib-utility/memorystream.h.

Referenced by Append().

◆ Data

std::array<uint8_t, ChunkSize> MemoryStream::Chunk::Data

Definition at line 44 of file lib-utility/memorystream.h.

Referenced by Append().


The documentation for this struct was generated from the following files: