From 7a447912216e467a402e48be49f143f1b4be8261 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Nov 2009 02:49:38 -0500 Subject: [PATCH] Optimization in the formatting of string values --- src/format.cc | 7 +++++-- src/value.cc | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/format.cc b/src/format.cc index e910ce3b..f26a86a1 100644 --- a/src/format.cc +++ b/src/format.cc @@ -355,8 +355,11 @@ string format_t::real_calc(scope_t& scope) } DEBUG("format.expr", "value = (" << value << ")"); - value.print(out, static_cast(elem->min_width), -1, - ! elem->has_flags(ELEMENT_ALIGN_LEFT)); + if (elem->min_width > 0) + value.print(out, static_cast(elem->min_width), -1, + ! elem->has_flags(ELEMENT_ALIGN_LEFT)); + else + out << value.to_string(); } catch (const calc_error&) { add_error_context(_("While calculating format expression:")); diff --git a/src/value.cc b/src/value.cc index ce852c2d..3f70ab3d 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1618,7 +1618,10 @@ void value_t::print(std::ostream& out, break; case STRING: - justify(out, as_string(), first_width, right_justify); + if (first_width > 0) + justify(out, as_string(), first_width, right_justify); + else + out << as_string(); break; case MASK: