Skip to content

Commit

Permalink
scripted-diff: rename base_blob::data to m_data
Browse files Browse the repository at this point in the history
Summary:
```
This is in preparation for exposing a ::data member function.

-BEGIN VERIFY SCRIPT-
sed -i "s/\([^.]\|other.\)data/\1m_data/g" src/uint256.h src/uint256.cpp
-END VERIFY SCRIPT-
```

Partial backport of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@131a2f0

The comparison fonction differs due to D1527.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9147
  • Loading branch information
sipa authored and Fabcien committed Feb 4, 2021
1 parent df2f217 commit 676c36c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
13 changes: 7 additions & 6 deletions src/uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

template <unsigned int BITS>
base_blob<BITS>::base_blob(const std::vector<uint8_t> &vch) {
assert(vch.size() == sizeof(data));
memcpy(data, vch.data(), sizeof(data));
assert(vch.size() == sizeof(m_data));
memcpy(m_data, vch.data(), sizeof(m_data));
}

template <unsigned int BITS> std::string base_blob<BITS>::GetHex() const {
return HexStr(std::reverse_iterator<const uint8_t *>(data + sizeof(data)),
std::reverse_iterator<const uint8_t *>(data));
return HexStr(
std::reverse_iterator<const uint8_t *>(m_data + sizeof(m_data)),
std::reverse_iterator<const uint8_t *>(m_data));
}

template <unsigned int BITS> void base_blob<BITS>::SetHex(const char *psz) {
memset(data, 0, sizeof(data));
memset(m_data, 0, sizeof(m_data));

// skip leading spaces
while (IsSpace(*psz)) {
Expand All @@ -37,7 +38,7 @@ template <unsigned int BITS> void base_blob<BITS>::SetHex(const char *psz) {
digits++;
}

uint8_t *p1 = (uint8_t *)data;
uint8_t *p1 = (uint8_t *)m_data;
uint8_t *pend = p1 + WIDTH;
while (digits > 0 && p1 < pend) {
*p1 = ::HexDigit(psz[--digits]);
Expand Down
30 changes: 15 additions & 15 deletions src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
template <unsigned int BITS> class base_blob {
protected:
static constexpr int WIDTH = BITS / 8;
uint8_t data[WIDTH];
uint8_t m_data[WIDTH];

public:
base_blob() { memset(data, 0, sizeof(data)); }
base_blob() { memset(m_data, 0, sizeof(m_data)); }

explicit base_blob(const std::vector<uint8_t> &vch);

bool IsNull() const {
for (int i = 0; i < WIDTH; i++) {
if (data[i] != 0) {
if (m_data[i] != 0) {
return false;
}
}
return true;
}

void SetNull() { memset(data, 0, sizeof(data)); }
void SetNull() { memset(m_data, 0, sizeof(m_data)); }

inline int Compare(const base_blob &other) const {
for (size_t i = 0; i < sizeof(data); i++) {
uint8_t a = data[sizeof(data) - 1 - i];
uint8_t b = other.data[sizeof(data) - 1 - i];
for (size_t i = 0; i < sizeof(m_data); i++) {
uint8_t a = m_data[sizeof(m_data) - 1 - i];
uint8_t b = other.m_data[sizeof(m_data) - 1 - i];
if (a > b) {
return 1;
}
Expand Down Expand Up @@ -73,30 +73,30 @@ template <unsigned int BITS> class base_blob {
void SetHex(const std::string &str);
std::string ToString() const { return GetHex(); }

uint8_t *begin() { return &data[0]; }
uint8_t *begin() { return &m_data[0]; }

uint8_t *end() { return &data[WIDTH]; }
uint8_t *end() { return &m_data[WIDTH]; }

const uint8_t *begin() const { return &data[0]; }
const uint8_t *begin() const { return &m_data[0]; }

const uint8_t *end() const { return &data[WIDTH]; }
const uint8_t *end() const { return &m_data[WIDTH]; }

unsigned int size() const { return sizeof(data); }
unsigned int size() const { return sizeof(m_data); }

uint64_t GetUint64(int pos) const {
const uint8_t *ptr = data + pos * 8;
const uint8_t *ptr = m_data + pos * 8;
return uint64_t(ptr[0]) | (uint64_t(ptr[1]) << 8) |
(uint64_t(ptr[2]) << 16) | (uint64_t(ptr[3]) << 24) |
(uint64_t(ptr[4]) << 32) | (uint64_t(ptr[5]) << 40) |
(uint64_t(ptr[6]) << 48) | (uint64_t(ptr[7]) << 56);
}

template <typename Stream> void Serialize(Stream &s) const {
s.write((char *)data, sizeof(data));
s.write((char *)m_data, sizeof(m_data));
}

template <typename Stream> void Unserialize(Stream &s) {
s.read((char *)data, sizeof(data));
s.read((char *)m_data, sizeof(m_data));
}
};

Expand Down

0 comments on commit 676c36c

Please sign in to comment.