Skip to content

Commit 078f7b9

Browse files
authored
Refactor doIndent (WebAssembly#4847)
Refactor everywhere from: ```c++ for (size_t i = 0; i < indent; i++) { o << ' '; } ``` to: ```c++ o << std::string(indent, ' '); ``` ### Motivation It is much simpler and should produce smaller code.See godbolt: https://godbolt.org/z/KMYMdn7z5
1 parent d02c260 commit 078f7b9

3 files changed

Lines changed: 3 additions & 14 deletions

File tree

src/dataflow/utils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
namespace wasm::DataFlow {
3333

3434
inline std::ostream& dump(Node* node, std::ostream& o, size_t indent = 0) {
35-
auto doIndent = [&]() {
36-
for (size_t i = 0; i < indent; i++) {
37-
o << ' ';
38-
}
39-
};
35+
auto doIndent = [&]() { o << std::string(indent, ' '); };
4036
doIndent();
4137
o << '[' << node << ' ';
4238
switch (node->type) {

src/passes/Print.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,11 +3538,7 @@ printStackInst(StackInst* inst, std::ostream& o, Function* func) {
35383538
static std::ostream&
35393539
printStackIR(StackIR* ir, std::ostream& o, Function* func) {
35403540
size_t indent = func ? 2 : 0;
3541-
auto doIndent = [&indent, &o]() {
3542-
for (size_t j = 0; j < indent; j++) {
3543-
o << ' ';
3544-
}
3545-
};
3541+
auto doIndent = [&]() { o << std::string(indent, ' '); };
35463542

35473543
int controlFlowDepth = 0;
35483544
// Stack to track indices of catches within a try

src/pretty_printing.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
#include "support/colors.h"
2727

2828
inline std::ostream& doIndent(std::ostream& o, unsigned indent) {
29-
for (unsigned i = 0; i < indent; i++) {
30-
o << " ";
31-
}
32-
return o;
29+
return o << std::string(indent, ' ');
3330
}
3431

3532
inline std::ostream& prepareMajorColor(std::ostream& o) {

0 commit comments

Comments
 (0)