summaryrefslogtreecommitdiff
path: root/src/format.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-19 12:49:25 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-19 12:49:25 -0400
commitcae49a2998965645a0eaa88ad702e2ebc9bd5434 (patch)
tree814f08572995542563ef573b0904270fccab6c47 /src/format.cc
parent2f083b8bdb88c8b3e33607c4894f88dfbe1f7564 (diff)
downloadfork-ledger-cae49a2998965645a0eaa88ad702e2ebc9bd5434.tar.gz
fork-ledger-cae49a2998965645a0eaa88ad702e2ebc9bd5434.tar.bz2
fork-ledger-cae49a2998965645a0eaa88ad702e2ebc9bd5434.zip
Efficiency fix for the formatting code
Diffstat (limited to 'src/format.cc')
-rw-r--r--src/format.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/format.cc b/src/format.cc
index e382f7ac..d2d7ebfd 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -262,18 +262,21 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
break;
}
- unistring temp(out.str());
+ if (elem->max_width > 0 || elem->min_width > 0) {
+ unistring temp(out.str());
- string result;
- if (elem->max_width > 0 && elem->max_width < temp.length()) {
- result = truncate(temp, elem->max_width);
+ string result;
+ if (elem->max_width > 0 && elem->max_width < temp.length()) {
+ result = truncate(temp, elem->max_width);
+ } else {
+ result = temp.extract();
+ for (int i = 0; i < (int)elem->min_width - (int)temp.length(); i++)
+ result += " ";
+ }
+ out_str << result;
} else {
- result = temp.extract();
- for (int i = 0; i < (int)elem->min_width - (int)temp.length(); i++)
- result += " ";
+ out_str << out.str();
}
-
- out_str << result;
}
}