Skip to content

Commit 8fc7140

Browse files
committed
Merge bitcoin/bitcoin#31671: Update leveldb subtree to latest upstream
910a11f build: remove LEVELDB_IS_BIG_ENDIAN (fanquake) d336b7a Squashed 'src/leveldb/' changes from 688561cba8..04b5790928 (fanquake) Pull request description: Includes: * bitcoin-core/leveldb-subtree#40 (used in #29852) * bitcoin-core/leveldb-subtree#45 * bitcoin-core/leveldb-subtree#46 ACKs for top commit: kevkevinpal: Concept ACK [910a11f](bitcoin/bitcoin@910a11f) l0rinc: ACK 910a11f hebasto: ACK 910a11f, I've performed a subtree update locally and got the same changes. theuni: utACK 910a11f Tree-SHA512: c5a2224c67d3fd598bc682589b805c324abf91003032a85764766048030285f56154779f29d3f0b3673c8f7f497ae62de5fc6b95ef0b022c873750053c7d27d5
2 parents a9edec9 + 910a11f commit 8fc7140

File tree

8 files changed

+8
-63
lines changed

8 files changed

+8
-63
lines changed

cmake/leveldb.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ target_compile_definitions(leveldb
6060
HAVE_FULLFSYNC=$<BOOL:${HAVE_FULLFSYNC}>
6161
HAVE_O_CLOEXEC=$<BOOL:${HAVE_O_CLOEXEC}>
6262
FALLTHROUGH_INTENDED=[[fallthrough]]
63-
LEVELDB_IS_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>
6463
$<$<NOT:$<BOOL:${WIN32}>>:LEVELDB_PLATFORM_POSIX>
6564
$<$<BOOL:${WIN32}>:LEVELDB_PLATFORM_WINDOWS>
6665
$<$<BOOL:${WIN32}>:_UNICODE;UNICODE>

src/leveldb/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)
2828
option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)
2929
option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
3030

31-
include(TestBigEndian)
32-
test_big_endian(LEVELDB_IS_BIG_ENDIAN)
33-
3431
include(CheckIncludeFile)
3532
check_include_file("unistd.h" HAVE_UNISTD_H)
3633

src/leveldb/include/leveldb/slice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class LEVELDB_EXPORT Slice {
5252
// Return true iff the length of the referenced data is zero
5353
bool empty() const { return size_ == 0; }
5454

55+
const char* begin() const { return data(); }
56+
const char* end() const { return data() + size(); }
57+
5558
// Return the ith byte in the referenced data.
5659
// REQUIRES: n < size()
5760
char operator[](size_t n) const {

src/leveldb/port/port_config.h.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@
3030
#cmakedefine01 HAVE_SNAPPY
3131
#endif // !defined(HAVE_SNAPPY)
3232

33-
// Define to 1 if your processor stores words with the most significant byte
34-
// first (like Motorola and SPARC, unlike Intel and VAX).
35-
#if !defined(LEVELDB_IS_BIG_ENDIAN)
36-
#cmakedefine01 LEVELDB_IS_BIG_ENDIAN
37-
#endif // !defined(LEVELDB_IS_BIG_ENDIAN)
38-
3933
#endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_

src/leveldb/port/port_example.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ namespace port {
1818
// TODO(jorlow): Many of these belong more in the environment class rather than
1919
// here. We should try moving them and see if it affects perf.
2020

21-
// The following boolean constant must be true on a little-endian machine
22-
// and false otherwise.
23-
static const bool kLittleEndian = true /* or some other expression */;
24-
2521
// ------------------ Threading -------------------
2622

2723
// A Mutex represents an exclusive lock.

src/leveldb/port/port_stdcxx.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
namespace leveldb {
4242
namespace port {
4343

44-
static const bool kLittleEndian = !LEVELDB_IS_BIG_ENDIAN;
45-
4644
class CondVar;
4745

4846
// Thinly wraps std::mutex.

src/leveldb/util/coding.h

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,13 @@ int VarintLength(uint64_t v);
4848
char* EncodeVarint32(char* dst, uint32_t value);
4949
char* EncodeVarint64(char* dst, uint64_t value);
5050

51-
// TODO(costan): Remove port::kLittleEndian and the fast paths based on
52-
// std::memcpy when clang learns to optimize the generic code, as
53-
// described in https://bugs.llvm.org/show_bug.cgi?id=41761
54-
//
55-
// The platform-independent code in DecodeFixed{32,64}() gets optimized to mov
56-
// on x86 and ldr on ARM64, by both clang and gcc. However, only gcc optimizes
57-
// the platform-independent code in EncodeFixed{32,64}() to mov / str.
58-
5951
// Lower-level versions of Put... that write directly into a character buffer
6052
// REQUIRES: dst has enough space for the value being written
6153

6254
inline void EncodeFixed32(char* dst, uint32_t value) {
6355
uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
6456

65-
if (port::kLittleEndian) {
66-
// Fast path for little-endian CPUs. All major compilers optimize this to a
67-
// single mov (x86_64) / str (ARM) instruction.
68-
std::memcpy(buffer, &value, sizeof(uint32_t));
69-
return;
70-
}
71-
72-
// Platform-independent code.
73-
// Currently, only gcc optimizes this to a single mov / str instruction.
57+
// Recent clang and gcc optimize this to a single mov / str instruction.
7458
buffer[0] = static_cast<uint8_t>(value);
7559
buffer[1] = static_cast<uint8_t>(value >> 8);
7660
buffer[2] = static_cast<uint8_t>(value >> 16);
@@ -80,15 +64,7 @@ inline void EncodeFixed32(char* dst, uint32_t value) {
8064
inline void EncodeFixed64(char* dst, uint64_t value) {
8165
uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
8266

83-
if (port::kLittleEndian) {
84-
// Fast path for little-endian CPUs. All major compilers optimize this to a
85-
// single mov (x86_64) / str (ARM) instruction.
86-
std::memcpy(buffer, &value, sizeof(uint64_t));
87-
return;
88-
}
89-
90-
// Platform-independent code.
91-
// Currently, only gcc optimizes this to a single mov / str instruction.
67+
// Recent clang and gcc optimize this to a single mov / str instruction.
9268
buffer[0] = static_cast<uint8_t>(value);
9369
buffer[1] = static_cast<uint8_t>(value >> 8);
9470
buffer[2] = static_cast<uint8_t>(value >> 16);
@@ -105,16 +81,7 @@ inline void EncodeFixed64(char* dst, uint64_t value) {
10581
inline uint32_t DecodeFixed32(const char* ptr) {
10682
const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr);
10783

108-
if (port::kLittleEndian) {
109-
// Fast path for little-endian CPUs. All major compilers optimize this to a
110-
// single mov (x86_64) / ldr (ARM) instruction.
111-
uint32_t result;
112-
std::memcpy(&result, buffer, sizeof(uint32_t));
113-
return result;
114-
}
115-
116-
// Platform-independent code.
117-
// Clang and gcc optimize this to a single mov / ldr instruction.
84+
// Recent clang and gcc optimize this to a single mov / ldr instruction.
11885
return (static_cast<uint32_t>(buffer[0])) |
11986
(static_cast<uint32_t>(buffer[1]) << 8) |
12087
(static_cast<uint32_t>(buffer[2]) << 16) |
@@ -124,16 +91,7 @@ inline uint32_t DecodeFixed32(const char* ptr) {
12491
inline uint64_t DecodeFixed64(const char* ptr) {
12592
const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr);
12693

127-
if (port::kLittleEndian) {
128-
// Fast path for little-endian CPUs. All major compilers optimize this to a
129-
// single mov (x86_64) / ldr (ARM) instruction.
130-
uint64_t result;
131-
std::memcpy(&result, buffer, sizeof(uint64_t));
132-
return result;
133-
}
134-
135-
// Platform-independent code.
136-
// Clang and gcc optimize this to a single mov / ldr instruction.
94+
// Recent clang and gcc optimize this to a single mov / ldr instruction.
13795
return (static_cast<uint64_t>(buffer[0])) |
13896
(static_cast<uint64_t>(buffer[1]) << 8) |
13997
(static_cast<uint64_t>(buffer[2]) << 16) |

src/leveldb/util/hash.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) {
2727
uint32_t h = seed ^ (n * m);
2828

2929
// Pick up four bytes at a time
30-
while (data + 4 <= limit) {
30+
while (limit - data >= 4) {
3131
uint32_t w = DecodeFixed32(data);
3232
data += 4;
3333
h += w;

0 commit comments

Comments
 (0)