Chromium Code Reviews| Index: runtime/vm/datastream.h |
| diff --git a/runtime/vm/datastream.h b/runtime/vm/datastream.h |
| index bb46e4f49943fa81f37260320bfea45154460b9c..e41e1006f6c639fab8010334d81aa3c0683dc139 100644 |
| --- a/runtime/vm/datastream.h |
| +++ b/runtime/vm/datastream.h |
| @@ -10,6 +10,7 @@ |
| #include "vm/allocation.h" |
| #include "vm/exceptions.h" |
| #include "vm/globals.h" |
| +#include "vm/os.h" |
| namespace dart { |
| @@ -386,6 +387,12 @@ class WriteStream : public ValueObject { |
| current_ += len; |
| } |
| + void Print(const char* format, ...) { |
| + va_list args; |
| + va_start(args, format); |
| + VPrint(format, args); |
| + } |
| + |
| private: |
| template<typename T> |
| void Write(T value) { |
| @@ -426,6 +433,28 @@ class WriteStream : public ValueObject { |
| ASSERT(end_ > *buffer_); |
| } |
| + void VPrint(const char* format, va_list args) { |
| + // Measure. |
| + va_list measure_args; |
| + va_copy(measure_args, args); |
| + intptr_t len = OS::VSNPrint(NULL, 0, format, measure_args); |
| + va_end(measure_args); |
| + |
| + // Alloc. |
| + if ((end_ - current_) < (len + 1)) { |
| + Resize(len + 1); |
| + } |
| + ASSERT((end_ - current_) >= (len + 1)); |
| + |
| + // Print. |
| + va_list print_args; |
| + va_copy(print_args, args); |
| + OS::VSNPrint(reinterpret_cast<char*>(current_), |
| + len + 1, format, print_args); |
| + va_end(print_args); |
| + current_ += len; // Not + 1 to swallow the terminating NUL. |
|
siva
2015/09/04 20:34:04
Not len + 1 to ...
rmacnak
2015/09/04 22:11:56
Done.
|
| + } |
| + |
| private: |
| uint8_t** const buffer_; |
| uint8_t* end_; |