From c4a0fdd2801df70ea5a543940f0ca1c5b0035ee2 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 5 Apr 2020 13:30:33 -0400 Subject: [PATCH] Reduce calls to rdbuf() in ostream_put --- include/boost/io/ios_state.hpp | 2 +- include/boost/io/ostream_put.hpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/boost/io/ios_state.hpp b/include/boost/io/ios_state.hpp index 0b58943..10bfd73 100644 --- a/include/boost/io/ios_state.hpp +++ b/include/boost/io/ios_state.hpp @@ -8,7 +8,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_IO_IOS_STATE_HPP #include -#include +#include #include #ifndef BOOST_NO_STD_LOCALE #include diff --git a/include/boost/io/ostream_put.hpp b/include/boost/io/ostream_put.hpp index 2e86ebe..998ad5c 100644 --- a/include/boost/io/ostream_put.hpp +++ b/include/boost/io/ostream_put.hpp @@ -18,27 +18,26 @@ namespace detail { template inline std::size_t -osp_put(std::basic_ostream& os, const charT* data, +osp_put(std::basic_streambuf& out, const charT* data, std::size_t size) { - return static_cast(os.rdbuf()->sputn(data, size)); + return static_cast(out.sputn(data, size)); } template inline bool -osp_fill(std::basic_ostream& os, std::size_t size) +osp_fill(std::basic_streambuf& out, charT c, std::size_t size) { - charT c = os.fill(); charT fill[] = { c, c, c, c, c, c, c, c }; enum { chunk = sizeof fill / sizeof(charT) }; for (; size > chunk; size -= chunk) { - if (boost::io::detail::osp_put(os, fill, chunk) != chunk) { + if (boost::io::detail::osp_put(out, fill, chunk) != chunk) { return false; } } - return boost::io::detail::osp_put(os, fill, size) == size; + return boost::io::detail::osp_put(out, fill, size) == size; } template @@ -75,18 +74,19 @@ ostream_put(std::basic_ostream& os, const charT* data, detail::osp_guard guard(os); typename stream::sentry entry(os); if (entry) { + std::basic_streambuf& out = *os.rdbuf(); std::size_t width = static_cast(os.width()); if (width <= size) { - if (detail::osp_put(os, data, size) != size) { + if (detail::osp_put(out, data, size) != size) { return os; } } else if ((os.flags() & stream::adjustfield) == stream::left) { - if (detail::osp_put(os, data, size) != size || - !detail::osp_fill(os, width - size)) { + if (detail::osp_put(out, data, size) != size || + !detail::osp_fill(out, os.fill(), width - size)) { return os; } - } else if (!detail::osp_fill(os, width - size) || - detail::osp_put(os, data, size) != size) { + } else if (!detail::osp_fill(out, os.fill(), width - size) || + detail::osp_put(out, data, size) != size) { return os; } os.width(0);