Index: runtime/vm/datastream.h |
diff --git a/runtime/vm/datastream.h b/runtime/vm/datastream.h |
index bb46e4f49943fa81f37260320bfea45154460b9c..f47e822bd8ed4657e9af80f79bb73f862f0ff1a2 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 len + 1 to swallow the terminating NUL. |
+ } |
+ |
private: |
uint8_t** const buffer_; |
uint8_t* end_; |