ART: Don't nest indenters in oatdump.
Reduces the time taken by the oatdump_test by ~12s (15%)
on host and ~55s (9%) on N5.
Change-Id: I99bb16ff5f3640389815f1fe54379ca64eac071b
diff --git a/runtime/indenter.h b/runtime/indenter.h
index 38b398d..78b18f6 100644
--- a/runtime/indenter.h
+++ b/runtime/indenter.h
@@ -19,10 +19,13 @@
#include "base/logging.h"
#include "base/macros.h"
+#include <ostream>
#include <streambuf>
-const char kIndentChar =' ';
-const size_t kIndentBy1Count = 2;
+namespace art {
+
+constexpr char kIndentChar =' ';
+constexpr size_t kIndentBy1Count = 2;
class Indenter : public std::streambuf {
public:
@@ -99,9 +102,60 @@
const char text_[8];
// Number of times text is output.
- const size_t count_;
+ size_t count_;
+
+ friend class VariableIndentationOutputStream;
DISALLOW_COPY_AND_ASSIGN(Indenter);
};
+class VariableIndentationOutputStream {
+ public:
+ explicit VariableIndentationOutputStream(std::ostream* os, char text = kIndentChar)
+ : indenter_(os->rdbuf(), text, 0u),
+ indented_os_(&indenter_) {
+ }
+
+ std::ostream& Stream() {
+ return indented_os_;
+ }
+
+ void IncreaseIndentation(size_t adjustment) {
+ indenter_.count_ += adjustment;
+ }
+
+ void DecreaseIndentation(size_t adjustment) {
+ DCHECK_GE(indenter_.count_, adjustment);
+ indenter_.count_ -= adjustment;
+ }
+
+ private:
+ Indenter indenter_;
+ std::ostream indented_os_;
+
+ DISALLOW_COPY_AND_ASSIGN(VariableIndentationOutputStream);
+};
+
+class ScopedIndentation {
+ public:
+ explicit ScopedIndentation(VariableIndentationOutputStream* vios,
+ size_t adjustment = kIndentBy1Count)
+ : vios_(vios),
+ adjustment_(adjustment) {
+ vios_->IncreaseIndentation(adjustment_);
+ }
+
+ ~ScopedIndentation() {
+ vios_->DecreaseIndentation(adjustment_);
+ }
+
+ private:
+ VariableIndentationOutputStream* const vios_;
+ const size_t adjustment_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedIndentation);
+};
+
+} // namespace art
+
#endif // ART_RUNTIME_INDENTER_H_