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

Unified Diff: courgette/streams.h

Issue 6677141: Switch out use of std::string and std::vector for large allocations for a buffer class that doesn... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix linux build error. remove unnecessary call Created 9 years, 8 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 | « courgette/memory_allocator.cc ('k') | courgette/streams.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/streams.h
===================================================================
--- courgette/streams.h (revision 80344)
+++ courgette/streams.h (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -121,21 +121,21 @@
~SinkStream() {}
// Appends |byte_count| bytes from |data| to the stream.
- CheckBool Write(const void* data, size_t byte_count);
+ CheckBool Write(const void* data, size_t byte_count) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32(uint32 value);
+ CheckBool WriteVarint32(uint32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32Signed(int32 value);
+ CheckBool WriteVarint32Signed(int32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
// On platforms where sizeof(size_t) != sizeof(int32), do a safety check.
- CheckBool WriteSizeVarint32(size_t value);
+ CheckBool WriteSizeVarint32(size_t value) WARN_UNUSED_RESULT;
// Contents of |other| are appended to |this| stream. The |other| stream
// becomes retired.
- CheckBool Append(SinkStream* other);
+ CheckBool Append(SinkStream* other) WARN_UNUSED_RESULT;
// Returns the number of bytes in this SinkStream
size_t Length() const { return buffer_.size(); }
@@ -144,26 +144,20 @@
// Writing to the stream invalidates the pointer. The SinkStream continues to
// own the memory.
const uint8* Buffer() const {
- return reinterpret_cast<const uint8*>(buffer_.c_str());
+ return reinterpret_cast<const uint8*>(buffer_.data());
}
// Hints that the stream will grow by an additional |length| bytes.
// Caller must be prepared to handle memory allocation problems.
- CheckBool Reserve(size_t length) {
- buffer_.reserve(length + buffer_.length());
- //TODO(tommi): return false when allocation fails.
- return true;
+ CheckBool Reserve(size_t length) WARN_UNUSED_RESULT {
+ return buffer_.reserve(length + buffer_.size());
}
// Finished with this stream and any storage it has.
void Retire();
private:
- // Use a string to manage the stream's memory.
- typedef std::basic_string<char,
- std::char_traits<char>,
- MemoryAllocator<char> > SinkBuffer;
- SinkBuffer buffer_;
+ NoThrowBuffer<char> buffer_;
DISALLOW_COPY_AND_ASSIGN(SinkStream);
};
@@ -222,15 +216,15 @@
// CopyTo serializes the streams in this SinkStreamSet into a single target
// stream. The serialized format may be re-read by initializing a
// SourceStreamSet with a buffer containing the data.
- CheckBool CopyTo(SinkStream* combined_stream);
+ CheckBool CopyTo(SinkStream* combined_stream) WARN_UNUSED_RESULT;
// Writes the streams of |set| into the corresponding streams of |this|.
// Stream zero first has some metadata written to it. |set| becomes retired.
// Partner to SourceStreamSet::ReadSet.
- CheckBool WriteSet(SinkStreamSet* set);
+ CheckBool WriteSet(SinkStreamSet* set) WARN_UNUSED_RESULT;
private:
- CheckBool CopyHeaderTo(SinkStream* stream);
+ CheckBool CopyHeaderTo(SinkStream* stream) WARN_UNUSED_RESULT;
size_t count_;
SinkStream streams_[kMaxStreams];
« no previous file with comments | « courgette/memory_allocator.cc ('k') | courgette/streams.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698