[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 33c0f82 3/4: Speed up ledger_format() [Ilja]
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 33c0f82 3/4: Speed up ledger_format() [Ilja] |
Date: |
Fri, 18 Jan 2019 08:50:51 -0500 (EST) |
branch: master
commit 33c0f82b596fa610528f175b3eaaef97900798b9
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Speed up ledger_format() [Ilja]
Initializing the std::stringstream OAOO (see recent changes in the unit
test) makes PDF generation about ten percent faster.
---
ledger_text_formats.cpp | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/ledger_text_formats.cpp b/ledger_text_formats.cpp
index 3497602..48eb6a6 100644
--- a/ledger_text_formats.cpp
+++ b/ledger_text_formats.cpp
@@ -1202,11 +1202,18 @@ std::string ledger_format
,std::pair<int,oenum_format_style> f
)
{
- std::stringstream interpreter;
- std::locale loc;
- std::locale new_loc(loc, new comma_punct);
- interpreter.imbue(new_loc);
- interpreter.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ static std::stringstream interpreter = []
+ {
+ std::stringstream ss {};
+ std::locale loc;
+ std::locale new_loc(loc, new comma_punct);
+ ss.imbue(new_loc);
+ ss.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ return ss;
+ } ();
+ interpreter.str(std::string{});
+ interpreter.clear();
+
interpreter.precision(f.first);
std::string s;
if(f.second)