Skip to content

Commit

Permalink
Merge pull request #211 from slaclab/ESROGUE-217
Browse files Browse the repository at this point in the history
Reduce iterations when adding buffers to a frame
  • Loading branch information
slacrherbst authored Apr 23, 2018
2 parents 032eab7 + 2397b23 commit 177817a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/rogue/interfaces/stream/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ris::Frame::BufferIterator ris::Frame::appendBuffer(ris::BufferPtr buff) {

buff->setFrame(shared_from_this());
buffers_.push_back(buff);
updateSizes();
sizeDirty_ = true;
return(buffers_.begin()+oSize);
}

Expand All @@ -70,9 +70,8 @@ ris::Frame::BufferIterator ris::Frame::appendFrame(ris::FramePtr frame) {
(*it)->setFrame(shared_from_this());
buffers_.push_back(*it);
}
frame->buffers_.clear();
frame->updateSizes();
updateSizes();
frame->clear();
sizeDirty_ = true;
return(buffers_.begin()+oSize);
}

Expand Down Expand Up @@ -102,8 +101,8 @@ bool ris::Frame::isEmpty() {
void ris::Frame::updateSizes() {
ris::Frame::BufferIterator it;

size_ = 0;
payload_ = 0;
size_ = 0;
payload_ = 0;

for (it = buffers_.begin(); it != buffers_.end(); ++it) {
payload_ += (*it)->getPayload();
Expand Down Expand Up @@ -199,7 +198,7 @@ void ris::Frame::minPayload(uint32_t size) {
if ( size > getPayload() ) setPayload(size);
}

//! Adjust payload size, TODO: Reduce iterations
//! Adjust payload size
void ris::Frame::adjustPayload(int32_t value) {
uint32_t size = getPayload();

Expand All @@ -213,22 +212,32 @@ void ris::Frame::adjustPayload(int32_t value) {
void ris::Frame::setPayloadFull() {
ris::Frame::BufferIterator it;

for (it = buffers_.begin(); it != buffers_.end(); ++it)
size_ = 0;
payload_ = 0;

for (it = buffers_.begin(); it != buffers_.end(); ++it) {
(*it)->setPayloadFull();

// Refresh
updateSizes();
payload_ += (*it)->getPayload();
size_ += (*it)->getSize();
}
sizeDirty_ = false;
}

//! Set the buffer as empty (minus header reservation)
void ris::Frame::setPayloadEmpty() {
ris::Frame::BufferIterator it;

for (it = buffers_.begin(); it != buffers_.end(); ++it)
size_ = 0;
payload_ = 0;

for (it = buffers_.begin(); it != buffers_.end(); ++it) {
(*it)->setPayloadEmpty();

// Refresh
updateSizes();
payload_ += (*it)->getPayload();
size_ += (*it)->getSize();
}
sizeDirty_ = false;
}

//! Get flags
Expand Down

0 comments on commit 177817a

Please sign in to comment.