From 6844ae1b8d6b9fcbe4fda5ac5cb0e5a4242d850a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 16 Sep 2018 18:30:39 +0000 Subject: tx_pool: avoid parsing a whole tx if only the prefix is needed --- src/serialization/serialization.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/serialization') diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 5fc382a1e..2050e88e2 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -318,7 +318,7 @@ namespace serialization { * \brief self explanatory */ template - bool do_check_stream_state(Stream& s, boost::mpl::bool_) + bool do_check_stream_state(Stream& s, boost::mpl::bool_, bool noeof) { return s.good(); } @@ -329,13 +329,13 @@ namespace serialization { * \detailed Also checks to make sure that the stream is not at EOF */ template - bool do_check_stream_state(Stream& s, boost::mpl::bool_) + bool do_check_stream_state(Stream& s, boost::mpl::bool_, bool noeof) { bool result = false; if (s.good()) { std::ios_base::iostate state = s.rdstate(); - result = EOF == s.peek(); + result = noeof || EOF == s.peek(); s.clear(state); } return result; @@ -347,9 +347,9 @@ namespace serialization { * \brief calls detail::do_check_stream_state for ar */ template - bool check_stream_state(Archive& ar) + bool check_stream_state(Archive& ar, bool noeof = false) { - return detail::do_check_stream_state(ar.stream(), typename Archive::is_saving()); + return detail::do_check_stream_state(ar.stream(), typename Archive::is_saving(), noeof); } /*! \fn serialize @@ -360,6 +360,17 @@ namespace serialization { inline bool serialize(Archive &ar, T &v) { bool r = do_serialize(ar, v); - return r && check_stream_state(ar); + return r && check_stream_state(ar, false); + } + + /*! \fn serialize + * + * \brief serializes \a v into \a ar + */ + template + inline bool serialize_noeof(Archive &ar, T &v) + { + bool r = do_serialize(ar, v); + return r && check_stream_state(ar, true); } } -- cgit v1.2.3