CopyOnWriteBuffer::SetSize to smaller size memcpy less.

R=kwiberg@webrtc.org

Review URL: https://codereview.webrtc.org/2317283004 .

Cr-Commit-Position: refs/heads/master@{#14166}
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h
index 72fb4ee..108aaa1 100644
--- a/webrtc/base/copyonwritebuffer.h
+++ b/webrtc/base/copyonwritebuffer.h
@@ -222,7 +222,13 @@
       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());
   }