Chromium Code Reviews| Index: base/values.cc |
| diff --git a/base/values.cc b/base/values.cc |
| index 459d56fa0222fa2ea98503ece9dd755022908725..1acc4365a9de0df9b29ec4b92e23a97a7dbb4b9e 100644 |
| --- a/base/values.cc |
| +++ b/base/values.cc |
| @@ -306,33 +306,32 @@ bool StringValue::Equals(const Value* other) const { |
| ///////////////////// BinaryValue //////////////////// |
| -BinaryValue::~BinaryValue() { |
| - DCHECK(buffer_); |
| - if (buffer_) |
| - delete[] buffer_; |
| +BinaryValue::BinaryValue() |
| + : Value(TYPE_BINARY), |
| + buffer_(NULL), |
| + size_(0) { |
| } |
| -// static |
| -BinaryValue* BinaryValue::Create(char* buffer, size_t size) { |
| - if (!buffer) |
| - return NULL; |
| +BinaryValue::BinaryValue(scoped_array<char> buffer, size_t size) |
| + : Value(TYPE_BINARY), |
| + buffer_(buffer.release()), |
|
brettw
2013/01/03 22:01:23
Can you use .Pass() here instead?
rpaquay
2013/01/03 23:20:02
Done.
|
| + size_(size) { |
| +} |
| - return new BinaryValue(buffer, size); |
| +BinaryValue::~BinaryValue() { |
| } |
| // static |
| BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, |
| size_t size) { |
| - if (!buffer) |
| - return NULL; |
| - |
| char* buffer_copy = new char[size]; |
| memcpy(buffer_copy, buffer, size); |
| - return new BinaryValue(buffer_copy, size); |
| + scoped_array<char> scoped_buffer_copy(buffer_copy); |
| + return new BinaryValue(scoped_buffer_copy.Pass(), size); |
| } |
| BinaryValue* BinaryValue::DeepCopy() const { |
| - return CreateWithCopiedBuffer(buffer_, size_); |
| + return CreateWithCopiedBuffer(buffer_.get(), size_); |
| } |
| bool BinaryValue::Equals(const Value* other) const { |
| @@ -341,14 +340,7 @@ bool BinaryValue::Equals(const Value* other) const { |
| const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); |
| if (other_binary->size_ != size_) |
| return false; |
| - return !memcmp(buffer_, other_binary->buffer_, size_); |
| -} |
| - |
| -BinaryValue::BinaryValue(char* buffer, size_t size) |
| - : Value(TYPE_BINARY), |
| - buffer_(buffer), |
| - size_(size) { |
| - DCHECK(buffer_); |
| + return !memcmp(GetBuffer(), other_binary->GetBuffer(), size_); |
| } |
| ///////////////////// DictionaryValue //////////////////// |