| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_DATASTREAM_H_ | 5 #ifndef RUNTIME_VM_DATASTREAM_H_ |
| 6 #define RUNTIME_VM_DATASTREAM_H_ | 6 #define RUNTIME_VM_DATASTREAM_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void Advance(intptr_t value) { | 85 void Advance(intptr_t value) { |
| 86 ASSERT((end_ - current_) > value); | 86 ASSERT((end_ - current_) > value); |
| 87 current_ = current_ + value; | 87 current_ = current_ + value; |
| 88 } | 88 } |
| 89 | 89 |
| 90 intptr_t PendingBytes() const { | 90 intptr_t PendingBytes() const { |
| 91 ASSERT(end_ >= current_); | 91 ASSERT(end_ >= current_); |
| 92 return (end_ - current_); | 92 return (end_ - current_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | |
| 96 template <typename T> | 95 template <typename T> |
| 97 T Read() { | 96 T Read() { |
| 98 return Read<T>(kEndByteMarker); | 97 return Read<T>(kEndByteMarker); |
| 99 } | 98 } |
| 100 | 99 |
| 100 private: |
| 101 int16_t Read16() { return Read16(kEndByteMarker); } | 101 int16_t Read16() { return Read16(kEndByteMarker); } |
| 102 | 102 |
| 103 int32_t Read32() { return Read32(kEndByteMarker); } | 103 int32_t Read32() { return Read32(kEndByteMarker); } |
| 104 | 104 |
| 105 int64_t Read64() { return Read64(kEndByteMarker); } | 105 int64_t Read64() { return Read64(kEndByteMarker); } |
| 106 | 106 |
| 107 template <typename T> | 107 template <typename T> |
| 108 T Read(uint8_t end_byte_marker) { | 108 T Read(uint8_t end_byte_marker) { |
| 109 const uint8_t* c = current_; | 109 const uint8_t* c = current_; |
| 110 ASSERT(c < end_); | 110 ASSERT(c < end_); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 *reinterpret_cast<uword*>(current_) = value; | 383 *reinterpret_cast<uword*>(current_) = value; |
| 384 current_ += len; | 384 current_ += len; |
| 385 } | 385 } |
| 386 | 386 |
| 387 void Print(const char* format, ...) { | 387 void Print(const char* format, ...) { |
| 388 va_list args; | 388 va_list args; |
| 389 va_start(args, format); | 389 va_start(args, format); |
| 390 VPrint(format, args); | 390 VPrint(format, args); |
| 391 } | 391 } |
| 392 | 392 |
| 393 private: | |
| 394 template <typename T> | 393 template <typename T> |
| 395 void Write(T value) { | 394 void Write(T value) { |
| 396 T v = value; | 395 T v = value; |
| 397 while (v < kMinDataPerByte || v > kMaxDataPerByte) { | 396 while (v < kMinDataPerByte || v > kMaxDataPerByte) { |
| 398 WriteByte(static_cast<uint8_t>(v & kByteMask)); | 397 WriteByte(static_cast<uint8_t>(v & kByteMask)); |
| 399 v = v >> kDataBitsPerByte; | 398 v = v >> kDataBitsPerByte; |
| 400 } | 399 } |
| 401 WriteByte(static_cast<uint8_t>(v + kEndByteMarker)); | 400 WriteByte(static_cast<uint8_t>(v + kEndByteMarker)); |
| 402 } | 401 } |
| 403 | 402 |
| 403 private: |
| 404 DART_FORCE_INLINE void WriteByte(uint8_t value) { | 404 DART_FORCE_INLINE void WriteByte(uint8_t value) { |
| 405 if (current_ >= end_) { | 405 if (current_ >= end_) { |
| 406 Resize(1); | 406 Resize(1); |
| 407 } | 407 } |
| 408 ASSERT(current_ < end_); | 408 ASSERT(current_ < end_); |
| 409 *current_++ = value; | 409 *current_++ = value; |
| 410 } | 410 } |
| 411 | 411 |
| 412 void Resize(intptr_t size_needed) { | 412 void Resize(intptr_t size_needed) { |
| 413 intptr_t position = current_ - *buffer_; | 413 intptr_t position = current_ - *buffer_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 intptr_t current_size_; | 457 intptr_t current_size_; |
| 458 ReAlloc alloc_; | 458 ReAlloc alloc_; |
| 459 intptr_t initial_size_; | 459 intptr_t initial_size_; |
| 460 | 460 |
| 461 DISALLOW_COPY_AND_ASSIGN(WriteStream); | 461 DISALLOW_COPY_AND_ASSIGN(WriteStream); |
| 462 }; | 462 }; |
| 463 | 463 |
| 464 } // namespace dart | 464 } // namespace dart |
| 465 | 465 |
| 466 #endif // RUNTIME_VM_DATASTREAM_H_ | 466 #endif // RUNTIME_VM_DATASTREAM_H_ |
| OLD | NEW |