Skip to content

Commit

Permalink
ring: only call dtor in pop & only reserve capacity in ctor
Browse files Browse the repository at this point in the history
filling values looks like resize the ring and it is wrong. less ctor
calls as a result
  • Loading branch information
wang-bin committed Dec 25, 2015
1 parent 8ffa31f commit ae18ec0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AVThread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AVThreadPrivate : public DPtrPrivate<AVThread>
, ready(false)
, render_pts0(-1)
, drop_frame_seek(true)
, pts_history(30, -1)
, pts_history(30)
{
tasks.blockFull(false);

Expand Down
2 changes: 1 addition & 1 deletion src/VideoThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void VideoThread::run()
qDebug("Invalid packet! flush video codec context!!!!!!!!!! video packet queue size: %d", d.packets.size());
d.dec->flush(); //d.dec instead of dec because d.dec maybe changed in processNextTask() but dec is not
d.render_pts0 = pkt.pts;
d.pts_history = ring<qreal>(d.pts_history.capacity(), -1);
d.pts_history = ring<qreal>(d.pts_history.capacity());
v_a = 0;
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ template<typename T>
class ring : public ring_api<T, std::vector<T> > {
using ring_api<T, std::vector<T> >::m_data; // why need this?
public:
ring(size_t capacity, const T& t = T()) : ring_api<T, std::vector<T> >() { m_data = std::vector<T>(capacity, t); }
size_t capacity() const {return m_data.size();}
ring(size_t capacity) : ring_api<T, std::vector<T> >() { m_data.reserve(capacity); }
size_t capacity() const {return m_data.capacity();}
};
template<typename T, int N>
class static_ring : public ring_api<T, T[N]> {
using ring_api<T, T[N]>::m_data; // why need this?
public:
static_ring(const T& t = T()) : ring_api<T, T[N]>() { for (int i = 0; i < N; ++i) {m_data[i] = t;}}
static_ring() : ring_api<T, T[N]>() {}
size_t capacity() const {return N;}
};

Expand All @@ -87,7 +87,7 @@ void ring_api<T,C>::pop_front() {
assert(!empty());
if (empty())
return;
m_data[m_0] = T(); //erase the old data
m_data[m_0].~T(); //erase the old data
m_0 = index(++m_0);
--m_s;
}
Expand Down

0 comments on commit ae18ec0

Please sign in to comment.