MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / append

Method append

app/src/IO/CircularBuffer.h:193–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191 */
192template<typename T, Concepts::ByteLike StorageType>
193void IO::CircularBuffer<T, StorageType>::append(const T& data)
194{
195 const qsizetype dataSize = data.size();
196 if (dataSize == 0) [[unlikely]]
197 return;
198
199 const uint8_t* src = reinterpret_cast<const uint8_t*>(data.data());
200
201 qsizetype copySize = dataSize;
202 if (copySize > m_capacity) [[unlikely]] {
203 src += (copySize - m_capacity);
204 copySize = m_capacity;
205 m_overflowCount.fetch_add(dataSize - m_capacity, std::memory_order_relaxed);
206 }
207
208 const qsizetype head = m_head.load(std::memory_order_acquire);
209 const qsizetype tail = m_tail.load(std::memory_order_relaxed);
210
211 qsizetype current_size = (tail >= head) ? (tail - head) : (m_capacity - head + tail);
212 qsizetype free_space = m_capacity - current_size;
213
214 if (copySize > free_space) [[unlikely]] {
215 const qsizetype overwrite = copySize - free_space;
216 m_overflowCount.fetch_add(overwrite, std::memory_order_relaxed);
217
218 const qsizetype new_head = (head + overwrite) & m_capacityMask;
219 m_head.store(new_head, std::memory_order_release);
220 }
221
222 const qsizetype firstChunk = std::min(copySize, m_capacity - tail);
223 std::memcpy(&m_buffer[tail], src, firstChunk);
224
225 if (copySize > firstChunk) [[unlikely]]
226 std::memcpy(&m_buffer[0], src + firstChunk, copySize - firstChunk);
227
228 const qsizetype new_tail = (tail + copySize) & m_capacityMask;
229 m_tail.store(new_tail, std::memory_order_release);
230}
231
232/**
233 * @brief Clears the buffer and modifies its maximum capacity.

Callers 15

availableBusesMethod · 0.45
onRawDataReceivedMethod · 0.45
appendChunkMethod · 0.45
setStartSequencesMethod · 0.45
setFinishSequencesMethod · 0.45
sendLineMethod · 0.45
appendLogMethod · 0.45
Checksum.cppFile · 0.45
processHexByteMethod · 0.45
processBin32ByteMethod · 0.45
processBinByteMethod · 0.45
sendZRQINITMethod · 0.45

Calls 3

sizeMethod · 0.45
dataMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected