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

Unified Diff: vm/datastream.h

Issue 10697055: Represent tokens as a compressed stream instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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 | « vm/benchmark_test.cc ('k') | vm/object.h » ('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 9536)
+++ vm/datastream.h (working copy)
@@ -18,6 +18,7 @@
static const int8_t kMinDataPerByte = -(1 << (kDataBitsPerByte - 1));
static const int8_t kMaxDataPerByte = (~kMinDataPerByte & kByteMask);
static const uint8_t kEndByteMarker = (255 - kMaxDataPerByte);
+static const uint8_t kEndUnsignedByteMarker = (255 - kMaxUnsignedDataPerByte);
typedef uint8_t* (*ReAlloc)(uint8_t* ptr, intptr_t old_size, intptr_t new_size);
@@ -63,18 +64,28 @@
}
};
+ // Reads 'len' bytes from the stream.
void ReadBytes(uint8_t* addr, intptr_t len) {
ASSERT((end_ - current_) >= len);
memmove(addr, current_, len);
current_ += len;
}
+ intptr_t ReadUnsigned() {
+ return Read<intptr_t>(kEndUnsignedByteMarker);
+ }
+
private:
template<typename T>
T Read() {
+ return Read<T>(kEndByteMarker);
+ }
+
+ template<typename T>
+ T Read(uint8_t end_byte_marker) {
uint8_t b = ReadByte();
if (b > kMaxUnsignedDataPerByte) {
- return static_cast<T>(b) - kEndByteMarker;
+ return static_cast<T>(b) - end_byte_marker;
}
T r = 0;
uint8_t s = 0;
@@ -83,7 +94,7 @@
s += kDataBitsPerByte;
b = ReadByte();
} while (b <= kMaxUnsignedDataPerByte);
- return r | ((static_cast<T>(b) - kEndByteMarker) << s);
+ return r | ((static_cast<T>(b) - end_byte_marker) << s);
}
uint8_t ReadByte() {
@@ -162,6 +173,15 @@
}
};
+ void WriteUnsigned(intptr_t value) {
+ ASSERT((value >= 0) && (value <= kIntptrMax));
+ while (value > kMaxUnsignedDataPerByte) {
+ WriteByte(static_cast<uint8_t>(value & kByteMask));
+ value = value >> kDataBitsPerByte;
+ }
+ WriteByte(static_cast<uint8_t>(value + kEndUnsignedByteMarker));
+ }
+
void WriteBytes(const uint8_t* addr, intptr_t len) {
if ((end_ - current_) < len) {
Resize(len);
« no previous file with comments | « vm/benchmark_test.cc ('k') | vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698