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

Unified Diff: runtime/vm/log.cc

Issue 913603002: Add Log::VPrint and remove duplicated code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « runtime/vm/log.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/log.cc
diff --git a/runtime/vm/log.cc b/runtime/vm/log.cc
index 6e8bb990f299c9a0d7a9abcf68a0ff8cf5fadadc..c62d8e56584b4c9004bfbb5499f818c1b9243639 100644
--- a/runtime/vm/log.cc
+++ b/runtime/vm/log.cc
@@ -22,24 +22,39 @@ void Log::Print(const char* format, ...) {
if (this == NoOpLog()) {
return;
}
- // Measure.
+
va_list args;
va_start(args, format);
- intptr_t len = OS::VSNPrint(NULL, 0, format, args);
+ VPrint(format, args);
va_end(args);
+}
- // Print string to buffer.
+
+void Log::VPrint(const char* format, va_list args) {
+ if (this == NoOpLog()) {
+ return;
+ }
+
+ // Measure.
+ va_list measure_args;
+ va_copy(measure_args, args);
+ intptr_t len = OS::VSNPrint(NULL, 0, format, measure_args);
+ va_end(measure_args);
+
+ // Print.
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
- va_list args2;
- va_start(args2, format);
- OS::VSNPrint(buffer, (len + 1), format, args2);
- va_end(args2);
+ va_list print_args;
+ va_copy(print_args, args);
+ OS::VSNPrint(buffer, (len + 1), format, print_args);
+ va_end(print_args);
- // Does not append the '\0' character.
+ // Append.
+ // NOTE: does not append the '\0' character.
for (intptr_t i = 0; i < len; i++) {
buffer_.Add(buffer[i]);
}
free(buffer);
+
if ((manual_flush_ == 0) || FLAG_force_log_flush) {
Flush();
}
« no previous file with comments | « runtime/vm/log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698