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

Unified Diff: vm/datastream.h

Issue 10665035: Prepare for writing token streams directly into a snapshot and reading it directly from the snapsho… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 | vm/raw_object_snapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/datastream.h
===================================================================
--- vm/datastream.h (revision 9070)
+++ vm/datastream.h (working copy)
@@ -6,6 +6,7 @@
#define VM_DATASTREAM_H_
#include "platform/assert.h"
+#include "platform/utils.h"
#include "vm/allocation.h"
#include "vm/globals.h"
@@ -63,7 +64,7 @@
};
void ReadBytes(uint8_t* addr, intptr_t len) {
- ASSERT((current_ + len) < end_);
+ ASSERT((end_ - current_) >= len);
memmove(addr, current_, len);
current_ += len;
}
@@ -102,7 +103,7 @@
// Stream for writing various types into a buffer.
class WriteStream : public ValueObject {
public:
- static const int kBufferIncrementSize = 64 * KB;
+ static const intptr_t kBufferIncrementSize = 64 * KB;
WriteStream(uint8_t** buffer, ReAlloc alloc) :
buffer_(buffer),
@@ -161,6 +162,15 @@
}
};
+ void WriteBytes(const uint8_t* addr, intptr_t len) {
+ if ((end_ - current_) < len) {
+ Resize(len);
+ }
+ ASSERT((end_ - current_) >= len);
+ memmove(current_, addr, len);
+ current_ += len;
+ }
+
private:
template<typename T>
void Write(T value) {
@@ -175,19 +185,26 @@
void WriteByte(uint8_t value) {
if (current_ >= end_) {
- intptr_t new_size = (current_size_ + kBufferIncrementSize);
- *buffer_ = reinterpret_cast<uint8_t*>(alloc_(*buffer_,
- current_size_,
- new_size));
- ASSERT(*buffer_ != NULL);
- current_ = *buffer_ + current_size_;
- current_size_ = new_size;
- end_ = *buffer_ + new_size;
+ Resize(1);
}
ASSERT(current_ < end_);
*current_++ = value;
}
+ void Resize(intptr_t size_needed) {
+ intptr_t position = current_ - *buffer_;
+ intptr_t new_size = current_size_ +
+ Utils::RoundUp(size_needed, kBufferIncrementSize);
+ *buffer_ = reinterpret_cast<uint8_t*>(alloc_(*buffer_,
+ current_size_,
+ new_size));
+ ASSERT(*buffer_ != NULL);
+ current_ = *buffer_ + position;
+ current_size_ = new_size;
+ end_ = *buffer_ + new_size;
+ ASSERT(end_ > *buffer_);
+ }
+
private:
uint8_t** const buffer_;
uint8_t* end_;
« no previous file with comments | « no previous file | vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698