From c2cab7a6a8dce13d8a0915be5f323491457d2eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 2 Dec 2021 18:17:41 +0300 Subject: [PATCH] mdbx: using `clang-format-13` (cosmetics). --- CMakeLists.txt | 4 +- mdbx.h++ | 31 ++++++---------- src/core.c | 99 +++++++++++++++++++++++++++----------------------- src/mdbx.c++ | 2 +- src/osal.c | 5 ++- 5 files changed, 72 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15fb4556..8c7d89d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,11 +298,11 @@ else() if(UNIX) 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) 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) - 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. add_custom_target(reformat VERBATIM diff --git a/mdbx.h++ b/mdbx.h++ index d47906ee..f0d689c6 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -477,30 +477,23 @@ static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, template concept MutableByteProducer = requires(T a, char array[42]) { - { a.is_empty() } - ->std::same_as; - { a.envisage_result_length() } - ->std::same_as; - { a.write_bytes(&array[0], size_t(42)) } - ->std::same_as; + { a.is_empty() } -> std::same_as; + { a.envisage_result_length() } -> std::same_as; + { a.write_bytes(&array[0], size_t(42)) } -> std::same_as; }; template concept ImmutableByteProducer = requires(const T &a, char array[42]) { - { a.is_empty() } - ->std::same_as; - { a.envisage_result_length() } - ->std::same_as; - { a.write_bytes(&array[0], size_t(42)) } - ->std::same_as; + { a.is_empty() } -> std::same_as; + { a.envisage_result_length() } -> std::same_as; + { a.write_bytes(&array[0], size_t(42)) } -> std::same_as; }; template -concept SliceTranscoder = - ImmutableByteProducer &&requires(const slice &source, const T &a) { +concept SliceTranscoder = ImmutableByteProducer && + requires(const slice &source, const T &a) { T(source); - { a.is_erroneous() } - ->std::same_as; + { a.is_erroneous() } -> std::same_as; }; #endif /* __cpp_concepts >= 201907L*/ @@ -4405,9 +4398,9 @@ MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept { const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length()); return diff ? diff - : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) - ? 0 - : memcmp(a.data(), b.data(), a.length()); + : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) + ? 0 + : memcmp(a.data(), b.data(), a.length()); } MDBX_CXX14_CONSTEXPR intptr_t diff --git a/src/core.c b/src/core.c index c3490505..a837a6a4 100644 --- a/src/core.c +++ b/src/core.c @@ -5102,9 +5102,9 @@ static unsigned spill_prio(const MDBX_txn *txn, const unsigned i, MDBX_page *const dp = dl->items[i].ptr; if (dp->mp_flags & (P_LOOSE | P_SPILLED)) { mdbx_debug("skip %s %u page %" PRIaPGNO, - (dp->mp_flags & P_LOOSE) - ? "loose" - : (dp->mp_flags & P_LOOSE) ? "loose" : "parent-spilled", + (dp->mp_flags & P_LOOSE) ? "loose" + : (dp->mp_flags & P_LOOSE) ? "loose" + : "parent-spilled", npages, pgno); return 256; } @@ -9204,7 +9204,8 @@ retry_noaccount: txn->tw.lifo_reclaimed ? (unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) - 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 (chunk < env->me_maxgc_ov1page * 2) chunk /= 2; @@ -9237,10 +9238,10 @@ retry_noaccount: } chunk = (avail >= tail) ? tail - span - : (avail_gc_slots > 3 && - reused_gc_slot < prefer_max_scatter - 3) - ? avail - span - : tail; + : (avail_gc_slots > 3 && + reused_gc_slot < prefer_max_scatter - 3) + ? avail - span + : tail; } } } @@ -10443,11 +10444,10 @@ __cold static int mdbx_read_header(MDBX_env *env, MDBX_meta *dest, unsigned guess_pagesize = 0; for (unsigned loop_count = 0; loop_count < loop_limit; ++loop_count) { const unsigned meta_number = loop_count % NUM_METAS; - const unsigned offset = - (guess_pagesize - ? guess_pagesize - : (loop_count > NUM_METAS) ? env->me_psize : env->me_os_psize) * - meta_number; + const unsigned offset = (guess_pagesize ? guess_pagesize + : (loop_count > NUM_METAS) ? env->me_psize + : env->me_os_psize) * + meta_number; char buffer[MIN_PAGESIZE]; unsigned retryleft = 42; @@ -10585,9 +10585,9 @@ static size_t mdbx_madvise_threshold(const MDBX_env *env, const unsigned factor = 9; const size_t threshold = (largest_bytes < (65536ul << factor)) ? 65536 /* minimal threshold */ - : (largest_bytes > (MEGABYTE * 4 << factor)) - ? MEGABYTE * 4 /* maximal threshold */ - : largest_bytes >> factor; + : (largest_bytes > (MEGABYTE * 4 << factor)) + ? MEGABYTE * 4 /* maximal threshold */ + : largest_bytes >> factor; return bytes_align2os_bytes(env, threshold); } #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 "/%" 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), meta0->mm_dbs[MAIN_DBI].md_root, meta0->mm_dbs[FREE_DBI].md_root); mdbx_debug("meta1: %s, %s, txn_id %" PRIaTXN ", root %" 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), meta1->mm_dbs[MAIN_DBI].md_root, meta1->mm_dbs[FREE_DBI].md_root); mdbx_debug("meta2: %s, %s, txn_id %" PRIaTXN ", root %" 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), 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) { const unsigned bytes = page_space(env); - env->me_merge_threshold = (uint16_t)( - bytes - (bytes * env->me_options.merge_threshold_16dot16_percent >> 16)); - env->me_merge_threshold_gc = (uint16_t)( - bytes - ((env->me_options.merge_threshold_16dot16_percent > 19005) - ? bytes / 3 /* 33 % */ - : bytes / 4 /* 25 % */)); + env->me_merge_threshold = + (uint16_t)(bytes - + (bytes * env->me_options.merge_threshold_16dot16_percent >> + 16)); + env->me_merge_threshold_gc = + (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) { @@ -14801,24 +14810,24 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data, rc = MDBX_NOTFOUND; exact = false; } else /* checking for early exit without dirtying pages */ - if (!(flags & (MDBX_RESERVE | MDBX_MULTIPLE)) && - unlikely(mc->mc_dbx->md_dcmp(data, &olddata) == 0)) { - if (!mc->mc_xcursor) - /* the same data, nothing to update */ - return MDBX_SUCCESS; - if (flags & MDBX_NODUPDATA) - return MDBX_KEYEXIST; - if (flags & MDBX_APPENDDUP) - return MDBX_EKEYMISMATCH; - if (likely(unsure_equal(mc->mc_dbx->md_dcmp, data, &olddata))) - /* data is match exactly byte-to-byte, nothing to update */ - return MDBX_SUCCESS; - else { - /* The data has differences, but the user-provided comparator - * considers them equal. So continue update since called without. - * Continue to update since was called without MDBX_NODUPDATA. */ + if (!(flags & (MDBX_RESERVE | MDBX_MULTIPLE)) && + unlikely(mc->mc_dbx->md_dcmp(data, &olddata) == 0)) { + if (!mc->mc_xcursor) + /* the same data, nothing to update */ + return MDBX_SUCCESS; + if (flags & MDBX_NODUPDATA) + return MDBX_KEYEXIST; + if (flags & MDBX_APPENDDUP) + return MDBX_EKEYMISMATCH; + if (likely(unsure_equal(mc->mc_dbx->md_dcmp, data, &olddata))) + /* data is match exactly byte-to-byte, nothing to update */ + return MDBX_SUCCESS; + else { + /* The data has differences, but the user-provided comparator + * considers them equal. So continue update since called without. + * Continue to update since was called without MDBX_NODUPDATA. */ + } } - } } } else if (unlikely(rc != MDBX_NOTFOUND)) 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) { - return (flags & MDBX_REVERSEKEY) - ? cmp_reverse - : (flags & MDBX_INTEGERKEY) ? cmp_int_align2 : cmp_lexical; + return (flags & MDBX_REVERSEKEY) ? cmp_reverse + : (flags & MDBX_INTEGERKEY) ? cmp_int_align2 + : cmp_lexical; } static __inline MDBX_cmp_func *get_default_datacmp(unsigned flags) { diff --git a/src/mdbx.c++ b/src/mdbx.c++ index e1e89942..ba3efb05 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -1429,7 +1429,7 @@ __cold ::std::ostream &operator<<(::std::ostream &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 { size_t one; const char *suffix; diff --git a/src/osal.c b/src/osal.c index 7f0d1c62..1432f314 100644 --- a/src/osal.c +++ b/src/osal.c @@ -1461,8 +1461,9 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, if (!NT_SUCCESS(err)) return ntstatus2errcode(err); - SIZE_T ViewSize = - (flags & MDBX_RDONLY) ? 0 : mdbx_RunningUnderWine() ? size : limit; + SIZE_T ViewSize = (flags & MDBX_RDONLY) ? 0 + : mdbx_RunningUnderWine() ? size + : limit; err = NtMapViewOfSection( map->section, GetCurrentProcess(), &map->address, /* ZeroBits */ 0,