Skip to content

Commit

Permalink
[core] Define an iterator for the srt::FixedArray.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Apr 20, 2022
1 parent 1cd39b9 commit 29d56be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 7 additions & 7 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ CRcvBufferNew::CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue,

CRcvBufferNew::~CRcvBufferNew()
{
for (size_t i = 0; i < m_szSize; ++i)
// Can be optimized by only iterating m_iMaxPosInc from m_iStartPos.
for (FixedArray<Entry>::iterator it = m_entries.begin(); it != m_entries.end(); ++it)
{
CUnit* unit = m_entries[i].pUnit;
if (unit != NULL)
{
m_pUnitQueue->makeUnitFree(unit);
m_entries[i].pUnit = NULL;
}
if (!it->pUnit)
continue;

m_pUnitQueue->makeUnitFree(it->pUnit);
it->pUnit = NULL;
}
}

Expand Down
13 changes: 12 additions & 1 deletion srtcore/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,18 @@ class FixedArray
return m_entries[index];
}

size_t size() const { return m_size; }
size_t size() const { return m_size; }

typedef T* iterator;
typedef const T* const_iterator;

iterator begin() { return m_entries; }
iterator end() { return m_entries + m_size; }

const_iterator cbegin() const { return m_entries; }
const_iterator cend() const { return m_entries + m_size; }

T* data() { return m_entries; }

private:
FixedArray(const FixedArray<T>& );
Expand Down

0 comments on commit 29d56be

Please sign in to comment.