diff --git a/src/ripple/app/paths/impl/BookStep.cpp b/src/ripple/app/paths/impl/BookStep.cpp index 7f046233c7..498cc3e574 100644 --- a/src/ripple/app/paths/impl/BookStep.cpp +++ b/src/ripple/app/paths/impl/BookStep.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +#include #include #include #include @@ -729,8 +730,7 @@ BookStep::revImp ( auto const r = forEachOffer (sb, afView, prevStepRedeems, eachOffer); boost::container::flat_set toRm = std::move(std::get<0>(r)); std::uint32_t const offersConsumed = std::get<1>(r); - ofrsToRm.insert (boost::container::ordered_unique_range_t{}, - toRm.begin (), toRm.end ()); + SetUnion(ofrsToRm, toRm); if (offersConsumed >= maxOffersToConsume_) { @@ -891,8 +891,7 @@ BookStep::fwdImp ( auto const r = forEachOffer (sb, afView, prevStepRedeems, eachOffer); boost::container::flat_set toRm = std::move(std::get<0>(r)); std::uint32_t const offersConsumed = std::get<1>(r); - ofrsToRm.insert (boost::container::ordered_unique_range_t{}, - toRm.begin (), toRm.end ()); + SetUnion(ofrsToRm, toRm); if (offersConsumed >= maxOffersToConsume_) { diff --git a/src/ripple/app/paths/impl/FlatSets.h b/src/ripple/app/paths/impl/FlatSets.h new file mode 100644 index 0000000000..0cf5ce8b86 --- /dev/null +++ b/src/ripple/app/paths/impl/FlatSets.h @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2019 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_APP_PATHS_IMPL_FLAT_SETS_H_INCLUDED +#define RIPPLE_APP_PATHS_IMPL_FLAT_SETS_H_INCLUDED + +#include + +namespace ripple { + +/** Given two flat sets dst and src, compute dst = dst union src + + @param dst set to store the resulting union, and also a source of elements for the union + @param src second source of elements for the union + */ +template +void +SetUnion( + boost::container::flat_set& dst, + boost::container::flat_set const& src) +{ + if (src.empty()) + return; + + dst.reserve(dst.size() + src.size()); + dst.insert( + boost::container::ordered_unique_range_t{}, src.begin(), src.end()); +} + +} // namespace ripple + +#endif diff --git a/src/ripple/app/paths/impl/StrandFlow.h b/src/ripple/app/paths/impl/StrandFlow.h index 205dcfe416..c6551012a2 100644 --- a/src/ripple/app/paths/impl/StrandFlow.h +++ b/src/ripple/app/paths/impl/StrandFlow.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -506,8 +507,7 @@ flow (PaymentSandbox const& baseView, sb, *strand, remainingIn, remainingOut, j); // rm bad offers even if the strand fails - ofrsToRm.insert (boost::container::ordered_unique_range_t{}, - f.ofrsToRm.begin (), f.ofrsToRm.end ()); + SetUnion(ofrsToRm, f.ofrsToRm); if (f.ter != tesSUCCESS || f.out == beast::zero) continue; @@ -589,8 +589,7 @@ flow (PaymentSandbox const& baseView, // view if (!ofrsToRm.empty ()) { - ofrsToRmOnFail.insert (boost::container::ordered_unique_range_t{}, - ofrsToRm.begin (), ofrsToRm.end ()); + SetUnion(ofrsToRmOnFail, ofrsToRm); for (auto const& o : ofrsToRm) { if (auto ok = sb.peek (keylet::offer (o)))