Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: webrtc/base/copyonwritebuffer.h

Issue 2317283004: CopyOnWriteBuffer::SetSize to smaller size memcpy less. (Closed)
Patch Set: Revert SetSize allowed to decrease capacity. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/copyonwritebuffer.h
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h
index 72fb4eea53495a2575ee435efade9d182afd4a69..108aaa19d7aae6aed91cda23bfe3f00a21183d0f 100644
--- a/webrtc/base/copyonwritebuffer.h
+++ b/webrtc/base/copyonwritebuffer.h
@@ -222,7 +222,13 @@ class CopyOnWriteBuffer {
return;
}
- CloneDataIfReferenced(std::max(buffer_->capacity(), size));
+ // Clone data if referenced.
+ if (!buffer_->HasOneRef()) {
+ buffer_ = new RefCountedObject<Buffer>(
+ buffer_->data(),
+ std::min(buffer_->size(), size),
+ std::max(buffer_->capacity(), size));
+ }
buffer_->SetSize(size);
RTC_DCHECK(IsConsistent());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698