tx_pool: avoid parsing a whole tx if only the prefix is needed

This commit is contained in:
moneromooo-monero 2018-09-16 18:30:39 +00:00
parent bb30a72367
commit 6844ae1b8d
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
5 changed files with 60 additions and 38 deletions

View file

@ -318,7 +318,7 @@ namespace serialization {
* \brief self explanatory
*/
template<class Stream>
bool do_check_stream_state(Stream& s, boost::mpl::bool_<true>)
bool do_check_stream_state(Stream& s, boost::mpl::bool_<true>, 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<class Stream>
bool do_check_stream_state(Stream& s, boost::mpl::bool_<false>)
bool do_check_stream_state(Stream& s, boost::mpl::bool_<false>, 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<class Archive>
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 <class Archive, class T>
inline bool serialize_noeof(Archive &ar, T &v)
{
bool r = do_serialize(ar, v);
return r && check_stream_state(ar, true);
}
}