lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 12cb7b9 2/4: Speed up stream_cast<>()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 12cb7b9 2/4: Speed up stream_cast<>()
Date: Fri, 18 Jan 2019 08:50:51 -0500 (EST)

branch: master
commit 12cb7b91d55bf41a92335438dec50c4085728d59
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Speed up stream_cast<>()
    
    Initializing the std::stringstream OAOO (see recent changes in the unit
    test) approximately doubles the speed.
---
 stream_cast.hpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/stream_cast.hpp b/stream_cast.hpp
index c9ed781..e9a8630 100644
--- a/stream_cast.hpp
+++ b/stream_cast.hpp
@@ -103,11 +103,16 @@ To stream_cast(From from, To = To())
         );
     static_assert(!std::is_pointer<To>::value);
 
-    std::stringstream interpreter;
-    std::ostringstream err;
     To result = To();
-
-    interpreter.imbue(blank_is_not_whitespace_locale());
+    std::ostringstream err;
+    static std::stringstream interpreter = []
+        {
+        std::stringstream ss {};
+        ss.imbue(blank_is_not_whitespace_locale());
+        return ss;
+        } ();
+    interpreter.str(std::string{});
+    interpreter.clear();
 
     if(!(interpreter << from))
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]