mdbx: using clang-format-13 (cosmetics).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2021-12-02 18:17:41 +03:00
parent 38df3ca5ad
commit c2cab7a6a8
5 changed files with 72 additions and 69 deletions

View File

@ -298,11 +298,11 @@ else()
if(UNIX) if(UNIX)
find_program(CLANG_FORMAT find_program(CLANG_FORMAT
NAMES clang-format-12 clang-format-11 clang-format-10 clang-format) NAMES clang-format-13 clang-format)
if(CLANG_FORMAT) if(CLANG_FORMAT)
execute_process(COMMAND ${CLANG_FORMAT} "--version" OUTPUT_VARIABLE clang_format_version_info) execute_process(COMMAND ${CLANG_FORMAT} "--version" OUTPUT_VARIABLE clang_format_version_info)
string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" clang_format_version_info CLANG_FORMAT_VERSION) string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" clang_format_version_info CLANG_FORMAT_VERSION)
if(clang_format_version_info AND NOT CLANG_FORMAT_VERSION VERSION_LESS 10.0) if(clang_format_version_info AND NOT CLANG_FORMAT_VERSION VERSION_LESS 13.0)
# Enable 'make reformat' target. # Enable 'make reformat' target.
add_custom_target(reformat add_custom_target(reformat
VERBATIM VERBATIM

View File

@ -477,30 +477,23 @@ static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src,
template <typename T> template <typename T>
concept MutableByteProducer = requires(T a, char array[42]) { concept MutableByteProducer = requires(T a, char array[42]) {
{ a.is_empty() } { a.is_empty() } -> std::same_as<bool>;
->std::same_as<bool>; { a.envisage_result_length() } -> std::same_as<size_t>;
{ a.envisage_result_length() } { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
->std::same_as<size_t>;
{ a.write_bytes(&array[0], size_t(42)) }
->std::same_as<char *>;
}; };
template <typename T> template <typename T>
concept ImmutableByteProducer = requires(const T &a, char array[42]) { concept ImmutableByteProducer = requires(const T &a, char array[42]) {
{ a.is_empty() } { a.is_empty() } -> std::same_as<bool>;
->std::same_as<bool>; { a.envisage_result_length() } -> std::same_as<size_t>;
{ a.envisage_result_length() } { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
->std::same_as<size_t>;
{ a.write_bytes(&array[0], size_t(42)) }
->std::same_as<char *>;
}; };
template <typename T> template <typename T>
concept SliceTranscoder = concept SliceTranscoder = ImmutableByteProducer<T> &&
ImmutableByteProducer<T> &&requires(const slice &source, const T &a) { requires(const slice &source, const T &a) {
T(source); T(source);
{ a.is_erroneous() } { a.is_erroneous() } -> std::same_as<bool>;
->std::same_as<bool>;
}; };
#endif /* __cpp_concepts >= 201907L*/ #endif /* __cpp_concepts >= 201907L*/
@ -4405,9 +4398,9 @@ MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a,
const slice &b) noexcept { const slice &b) noexcept {
const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length()); const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
return diff ? diff return diff ? diff
: MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data())
? 0 ? 0
: memcmp(a.data(), b.data(), a.length()); : memcmp(a.data(), b.data(), a.length());
} }
MDBX_CXX14_CONSTEXPR intptr_t MDBX_CXX14_CONSTEXPR intptr_t

View File

@ -5102,9 +5102,9 @@ static unsigned spill_prio(const MDBX_txn *txn, const unsigned i,
MDBX_page *const dp = dl->items[i].ptr; MDBX_page *const dp = dl->items[i].ptr;
if (dp->mp_flags & (P_LOOSE | P_SPILLED)) { if (dp->mp_flags & (P_LOOSE | P_SPILLED)) {
mdbx_debug("skip %s %u page %" PRIaPGNO, mdbx_debug("skip %s %u page %" PRIaPGNO,
(dp->mp_flags & P_LOOSE) (dp->mp_flags & P_LOOSE) ? "loose"
? "loose" : (dp->mp_flags & P_LOOSE) ? "loose"
: (dp->mp_flags & P_LOOSE) ? "loose" : "parent-spilled", : "parent-spilled",
npages, pgno); npages, pgno);
return 256; return 256;
} }
@ -9204,7 +9204,8 @@ retry_noaccount:
txn->tw.lifo_reclaimed txn->tw.lifo_reclaimed
? (unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) - ? (unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) -
reused_gc_slot + 1 reused_gc_slot + 1
: (gc_rid < INT16_MAX) ? (unsigned)gc_rid : INT16_MAX; : (gc_rid < INT16_MAX) ? (unsigned)gc_rid
: INT16_MAX;
if (avail_gc_slots > 1) { if (avail_gc_slots > 1) {
if (chunk < env->me_maxgc_ov1page * 2) if (chunk < env->me_maxgc_ov1page * 2)
chunk /= 2; chunk /= 2;
@ -9237,10 +9238,10 @@ retry_noaccount:
} }
chunk = (avail >= tail) ? tail - span chunk = (avail >= tail) ? tail - span
: (avail_gc_slots > 3 && : (avail_gc_slots > 3 &&
reused_gc_slot < prefer_max_scatter - 3) reused_gc_slot < prefer_max_scatter - 3)
? avail - span ? avail - span
: tail; : tail;
} }
} }
} }
@ -10443,11 +10444,10 @@ __cold static int mdbx_read_header(MDBX_env *env, MDBX_meta *dest,
unsigned guess_pagesize = 0; unsigned guess_pagesize = 0;
for (unsigned loop_count = 0; loop_count < loop_limit; ++loop_count) { for (unsigned loop_count = 0; loop_count < loop_limit; ++loop_count) {
const unsigned meta_number = loop_count % NUM_METAS; const unsigned meta_number = loop_count % NUM_METAS;
const unsigned offset = const unsigned offset = (guess_pagesize ? guess_pagesize
(guess_pagesize : (loop_count > NUM_METAS) ? env->me_psize
? guess_pagesize : env->me_os_psize) *
: (loop_count > NUM_METAS) ? env->me_psize : env->me_os_psize) * meta_number;
meta_number;
char buffer[MIN_PAGESIZE]; char buffer[MIN_PAGESIZE];
unsigned retryleft = 42; unsigned retryleft = 42;
@ -10585,9 +10585,9 @@ static size_t mdbx_madvise_threshold(const MDBX_env *env,
const unsigned factor = 9; const unsigned factor = 9;
const size_t threshold = (largest_bytes < (65536ul << factor)) const size_t threshold = (largest_bytes < (65536ul << factor))
? 65536 /* minimal threshold */ ? 65536 /* minimal threshold */
: (largest_bytes > (MEGABYTE * 4 << factor)) : (largest_bytes > (MEGABYTE * 4 << factor))
? MEGABYTE * 4 /* maximal threshold */ ? MEGABYTE * 4 /* maximal threshold */
: largest_bytes >> factor; : largest_bytes >> factor;
return bytes_align2os_bytes(env, threshold); return bytes_align2os_bytes(env, threshold);
} }
#endif /* MDBX_ENABLE_MADVISE */ #endif /* MDBX_ENABLE_MADVISE */
@ -10802,17 +10802,23 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
mdbx_debug("meta0: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO mdbx_debug("meta0: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO
"/%" PRIaPGNO, "/%" PRIaPGNO,
(meta0 == head) ? "head" : (meta0 == target) ? "tail" : "stay", (meta0 == head) ? "head"
: (meta0 == target) ? "tail"
: "stay",
mdbx_durable_str(meta0), mdbx_meta_txnid_fluid(env, meta0), mdbx_durable_str(meta0), mdbx_meta_txnid_fluid(env, meta0),
meta0->mm_dbs[MAIN_DBI].md_root, meta0->mm_dbs[FREE_DBI].md_root); meta0->mm_dbs[MAIN_DBI].md_root, meta0->mm_dbs[FREE_DBI].md_root);
mdbx_debug("meta1: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO mdbx_debug("meta1: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO
"/%" PRIaPGNO, "/%" PRIaPGNO,
(meta1 == head) ? "head" : (meta1 == target) ? "tail" : "stay", (meta1 == head) ? "head"
: (meta1 == target) ? "tail"
: "stay",
mdbx_durable_str(meta1), mdbx_meta_txnid_fluid(env, meta1), mdbx_durable_str(meta1), mdbx_meta_txnid_fluid(env, meta1),
meta1->mm_dbs[MAIN_DBI].md_root, meta1->mm_dbs[FREE_DBI].md_root); meta1->mm_dbs[MAIN_DBI].md_root, meta1->mm_dbs[FREE_DBI].md_root);
mdbx_debug("meta2: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO mdbx_debug("meta2: %s, %s, txn_id %" PRIaTXN ", root %" PRIaPGNO
"/%" PRIaPGNO, "/%" PRIaPGNO,
(meta2 == head) ? "head" : (meta2 == target) ? "tail" : "stay", (meta2 == head) ? "head"
: (meta2 == target) ? "tail"
: "stay",
mdbx_durable_str(meta2), mdbx_meta_txnid_fluid(env, meta2), mdbx_durable_str(meta2), mdbx_meta_txnid_fluid(env, meta2),
meta2->mm_dbs[MAIN_DBI].md_root, meta2->mm_dbs[FREE_DBI].md_root); meta2->mm_dbs[MAIN_DBI].md_root, meta2->mm_dbs[FREE_DBI].md_root);
@ -10935,12 +10941,15 @@ fail:
static void recalculate_merge_threshold(MDBX_env *env) { static void recalculate_merge_threshold(MDBX_env *env) {
const unsigned bytes = page_space(env); const unsigned bytes = page_space(env);
env->me_merge_threshold = (uint16_t)( env->me_merge_threshold =
bytes - (bytes * env->me_options.merge_threshold_16dot16_percent >> 16)); (uint16_t)(bytes -
env->me_merge_threshold_gc = (uint16_t)( (bytes * env->me_options.merge_threshold_16dot16_percent >>
bytes - ((env->me_options.merge_threshold_16dot16_percent > 19005) 16));
? bytes / 3 /* 33 % */ env->me_merge_threshold_gc =
: bytes / 4 /* 25 % */)); (uint16_t)(bytes -
((env->me_options.merge_threshold_16dot16_percent > 19005)
? bytes / 3 /* 33 % */
: bytes / 4 /* 25 % */));
} }
__cold static void mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) { __cold static void mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) {
@ -14801,24 +14810,24 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
rc = MDBX_NOTFOUND; rc = MDBX_NOTFOUND;
exact = false; exact = false;
} else /* checking for early exit without dirtying pages */ } else /* checking for early exit without dirtying pages */
if (!(flags & (MDBX_RESERVE | MDBX_MULTIPLE)) && if (!(flags & (MDBX_RESERVE | MDBX_MULTIPLE)) &&
unlikely(mc->mc_dbx->md_dcmp(data, &olddata) == 0)) { unlikely(mc->mc_dbx->md_dcmp(data, &olddata) == 0)) {
if (!mc->mc_xcursor) if (!mc->mc_xcursor)
/* the same data, nothing to update */ /* the same data, nothing to update */
return MDBX_SUCCESS; return MDBX_SUCCESS;
if (flags & MDBX_NODUPDATA) if (flags & MDBX_NODUPDATA)
return MDBX_KEYEXIST; return MDBX_KEYEXIST;
if (flags & MDBX_APPENDDUP) if (flags & MDBX_APPENDDUP)
return MDBX_EKEYMISMATCH; return MDBX_EKEYMISMATCH;
if (likely(unsure_equal(mc->mc_dbx->md_dcmp, data, &olddata))) if (likely(unsure_equal(mc->mc_dbx->md_dcmp, data, &olddata)))
/* data is match exactly byte-to-byte, nothing to update */ /* data is match exactly byte-to-byte, nothing to update */
return MDBX_SUCCESS; return MDBX_SUCCESS;
else { else {
/* The data has differences, but the user-provided comparator /* The data has differences, but the user-provided comparator
* considers them equal. So continue update since called without. * considers them equal. So continue update since called without.
* Continue to update since was called without MDBX_NODUPDATA. */ * Continue to update since was called without MDBX_NODUPDATA. */
}
} }
}
} }
} else if (unlikely(rc != MDBX_NOTFOUND)) } else if (unlikely(rc != MDBX_NOTFOUND))
return rc; return rc;
@ -19575,9 +19584,9 @@ __cold int mdbx_env_info_ex(const MDBX_env *env, const MDBX_txn *txn,
} }
static __inline MDBX_cmp_func *get_default_keycmp(unsigned flags) { static __inline MDBX_cmp_func *get_default_keycmp(unsigned flags) {
return (flags & MDBX_REVERSEKEY) return (flags & MDBX_REVERSEKEY) ? cmp_reverse
? cmp_reverse : (flags & MDBX_INTEGERKEY) ? cmp_int_align2
: (flags & MDBX_INTEGERKEY) ? cmp_int_align2 : cmp_lexical; : cmp_lexical;
} }
static __inline MDBX_cmp_func *get_default_datacmp(unsigned flags) { static __inline MDBX_cmp_func *get_default_datacmp(unsigned flags) {

View File

@ -1429,7 +1429,7 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
} }
const auto bytes = (it.bytes < 0) ? out << "-", const auto bytes = (it.bytes < 0) ? out << "-",
size_t(-it.bytes) : size_t(it.bytes); size_t(-it.bytes) : size_t(it.bytes);
struct { struct {
size_t one; size_t one;
const char *suffix; const char *suffix;

View File

@ -1461,8 +1461,9 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
if (!NT_SUCCESS(err)) if (!NT_SUCCESS(err))
return ntstatus2errcode(err); return ntstatus2errcode(err);
SIZE_T ViewSize = SIZE_T ViewSize = (flags & MDBX_RDONLY) ? 0
(flags & MDBX_RDONLY) ? 0 : mdbx_RunningUnderWine() ? size : limit; : mdbx_RunningUnderWine() ? size
: limit;
err = NtMapViewOfSection( err = NtMapViewOfSection(
map->section, GetCurrentProcess(), &map->address, map->section, GetCurrentProcess(), &map->address,
/* ZeroBits */ 0, /* ZeroBits */ 0,