summaryrefslogtreecommitdiffstats
path: root/remoting/base/compound_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/base/compound_buffer.cc')
-rw-r--r--remoting/base/compound_buffer.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/remoting/base/compound_buffer.cc b/remoting/base/compound_buffer.cc
index 9e8b8c3..2808f6d 100644
--- a/remoting/base/compound_buffer.cc
+++ b/remoting/base/compound_buffer.cc
@@ -88,6 +88,49 @@ void CompoundBuffer::PrependCopyOf(const char* data, int size) {
Prepend(buffer, size);
}
+void CompoundBuffer::CropFront(int bytes) {
+ CHECK(!locked_);
+
+ if (total_bytes_ <= bytes) {
+ Clear();
+ return;
+ }
+
+ total_bytes_ -= bytes;
+ while (chunks_.size() > 0 && chunks_.front().size <= bytes) {
+ bytes -= chunks_.front().size;
+ chunks_.pop_front();
+ }
+ if (chunks_.size() > 0 && bytes > 0) {
+ chunks_.front().start += bytes;
+ chunks_.front().size -= bytes;
+ DCHECK_GT(chunks_.front().size, 0);
+ bytes = 0;
+ }
+ DCHECK_EQ(bytes, 0);
+}
+
+void CompoundBuffer::CropBack(int bytes) {
+ CHECK(!locked_);
+
+ if (total_bytes_ <= bytes) {
+ Clear();
+ return;
+ }
+
+ total_bytes_ -= bytes;
+ while (chunks_.size() > 0 && chunks_.back().size <= bytes) {
+ bytes -= chunks_.back().size;
+ chunks_.pop_back();
+ }
+ if (chunks_.size() > 0 && bytes > 0) {
+ chunks_.back().size -= bytes;
+ DCHECK_GT(chunks_.back().size, 0);
+ bytes = 0;
+ }
+ DCHECK_EQ(bytes, 0);
+}
+
void CompoundBuffer::Lock() {
locked_ = true;
}