Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base_uint now compares and assigns with beast::Zero. #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions src/ripple/types/api/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
#include "Blob.h"
#include "strHex.h"
#include "ByteOrder.h"

#include "../../../beast/beast/container/hardened_hash.h"
#include "../../../beast/beast/utility/Zero.h"

using beast::zero;
using beast::Zero;

#include <functional>

Expand Down Expand Up @@ -147,7 +151,7 @@ class base_uint
}

base_uint (base_uint const& other) = default;

/* Construct from a raw pointer.
The buffer pointed to by `data` must be at least Bits/8 bytes.
*/
Expand Down Expand Up @@ -385,6 +389,12 @@ class base_uint
{
memset (&pn[0], 0, sizeof (pn));
}

base_uint<Bits, Tag>& operator=(Zero)
{
zero();
return *this;
}
};

typedef base_uint<128> uint128;
Expand All @@ -396,9 +406,37 @@ extern std::size_t hash_value (uint128 const&);
extern std::size_t hash_value (uint160 const&);
extern std::size_t hash_value (uint256 const&);


//------------------------------------------------------------------------------

template <std::size_t Bits, class Tag>
bool operator==(base_uint<Bits, Tag> const& u, Zero)
{
return u.isZero();
}

template <std::size_t Bits, class Tag>
bool operator==(Zero, base_uint<Bits, Tag> const& u)
{
return u == zero;
}

template <std::size_t Bits, class Tag>
bool operator!=(base_uint<Bits, Tag> const& u, Zero)
{
return !(u == zero);
}

template <std::size_t Bits, class Tag>
bool operator!=(Zero, base_uint<Bits, Tag> const& u)
{
return !(u == zero);
}


//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
int
int
compare (base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
auto ret = std::mismatch (a.cbegin (), a.cend (), b.cbegin ());
Expand Down
4 changes: 0 additions & 4 deletions src/ripple_basics/ripple_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#include <atomic>
#include "../../beast/beast/cxx14/memory.h"
#include "../../beast/beast/utility/Zero.h"

using beast::zero;
using beast::Zero;

#ifndef RIPPLE_TRACK_MUTEXES
# define RIPPLE_TRACK_MUTEXES 0
Expand Down