mirror of
https://github.com/isar/libmdbx.git
synced 2025-09-11 01:52:19 +08:00
mdbx: новые настройки clang-format (косметика).
This commit is contained in:
60
src/pnl.c
60
src/pnl.c
@@ -25,14 +25,11 @@ MDBX_INTERNAL void pnl_free(pnl_t pnl) {
|
||||
|
||||
MDBX_INTERNAL void pnl_shrink(pnl_t __restrict *__restrict ppnl) {
|
||||
assert(pnl_bytes2size(pnl_size2bytes(MDBX_PNL_INITIAL)) >= MDBX_PNL_INITIAL &&
|
||||
pnl_bytes2size(pnl_size2bytes(MDBX_PNL_INITIAL)) <
|
||||
MDBX_PNL_INITIAL * 3 / 2);
|
||||
assert(MDBX_PNL_GETSIZE(*ppnl) <= PAGELIST_LIMIT &&
|
||||
MDBX_PNL_ALLOCLEN(*ppnl) >= MDBX_PNL_GETSIZE(*ppnl));
|
||||
pnl_bytes2size(pnl_size2bytes(MDBX_PNL_INITIAL)) < MDBX_PNL_INITIAL * 3 / 2);
|
||||
assert(MDBX_PNL_GETSIZE(*ppnl) <= PAGELIST_LIMIT && MDBX_PNL_ALLOCLEN(*ppnl) >= MDBX_PNL_GETSIZE(*ppnl));
|
||||
MDBX_PNL_SETSIZE(*ppnl, 0);
|
||||
if (unlikely(MDBX_PNL_ALLOCLEN(*ppnl) >
|
||||
MDBX_PNL_INITIAL * (MDBX_PNL_PREALLOC_FOR_RADIXSORT ? 8 : 4) -
|
||||
MDBX_CACHELINE_SIZE / sizeof(pgno_t))) {
|
||||
MDBX_PNL_INITIAL * (MDBX_PNL_PREALLOC_FOR_RADIXSORT ? 8 : 4) - MDBX_CACHELINE_SIZE / sizeof(pgno_t))) {
|
||||
size_t bytes = pnl_size2bytes(MDBX_PNL_INITIAL * 2);
|
||||
pnl_t pnl = osal_realloc(*ppnl - 1, bytes);
|
||||
if (likely(pnl)) {
|
||||
@@ -45,11 +42,9 @@ MDBX_INTERNAL void pnl_shrink(pnl_t __restrict *__restrict ppnl) {
|
||||
}
|
||||
}
|
||||
|
||||
MDBX_INTERNAL int pnl_reserve(pnl_t __restrict *__restrict ppnl,
|
||||
const size_t wanna) {
|
||||
MDBX_INTERNAL int pnl_reserve(pnl_t __restrict *__restrict ppnl, const size_t wanna) {
|
||||
const size_t allocated = MDBX_PNL_ALLOCLEN(*ppnl);
|
||||
assert(MDBX_PNL_GETSIZE(*ppnl) <= PAGELIST_LIMIT &&
|
||||
MDBX_PNL_ALLOCLEN(*ppnl) >= MDBX_PNL_GETSIZE(*ppnl));
|
||||
assert(MDBX_PNL_GETSIZE(*ppnl) <= PAGELIST_LIMIT && MDBX_PNL_ALLOCLEN(*ppnl) >= MDBX_PNL_GETSIZE(*ppnl));
|
||||
if (likely(allocated >= wanna))
|
||||
return MDBX_SUCCESS;
|
||||
|
||||
@@ -58,9 +53,7 @@ MDBX_INTERNAL int pnl_reserve(pnl_t __restrict *__restrict ppnl,
|
||||
return MDBX_TXN_FULL;
|
||||
}
|
||||
|
||||
const size_t size = (wanna + wanna - allocated < PAGELIST_LIMIT)
|
||||
? wanna + wanna - allocated
|
||||
: PAGELIST_LIMIT;
|
||||
const size_t size = (wanna + wanna - allocated < PAGELIST_LIMIT) ? wanna + wanna - allocated : PAGELIST_LIMIT;
|
||||
size_t bytes = pnl_size2bytes(size);
|
||||
pnl_t pnl = osal_realloc(*ppnl - 1, bytes);
|
||||
if (likely(pnl)) {
|
||||
@@ -75,8 +68,8 @@ MDBX_INTERNAL int pnl_reserve(pnl_t __restrict *__restrict ppnl,
|
||||
return MDBX_ENOMEM;
|
||||
}
|
||||
|
||||
static __always_inline int __must_check_result pnl_append_stepped(
|
||||
unsigned step, __restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
static __always_inline int __must_check_result pnl_append_stepped(unsigned step, __restrict pnl_t *ppnl, pgno_t pgno,
|
||||
size_t n) {
|
||||
assert(n > 0);
|
||||
int rc = pnl_need(ppnl, n);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
@@ -106,18 +99,15 @@ static __always_inline int __must_check_result pnl_append_stepped(
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
__hot MDBX_INTERNAL int __must_check_result
|
||||
spill_append_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
__hot MDBX_INTERNAL int __must_check_result spill_append_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
return pnl_append_stepped(2, ppnl, pgno << 1, n);
|
||||
}
|
||||
|
||||
__hot MDBX_INTERNAL int __must_check_result
|
||||
pnl_append_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
__hot MDBX_INTERNAL int __must_check_result pnl_append_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
return pnl_append_stepped(1, ppnl, pgno, n);
|
||||
}
|
||||
|
||||
__hot MDBX_INTERNAL int __must_check_result
|
||||
pnl_insert_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
__hot MDBX_INTERNAL int __must_check_result pnl_insert_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
assert(n > 0);
|
||||
int rc = pnl_need(ppnl, n);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
@@ -135,8 +125,7 @@ pnl_insert_span(__restrict pnl_t *ppnl, pgno_t pgno, size_t n) {
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
__hot __noinline MDBX_INTERNAL bool pnl_check(const const_pnl_t pnl,
|
||||
const size_t limit) {
|
||||
__hot __noinline MDBX_INTERNAL bool pnl_check(const const_pnl_t pnl, const size_t limit) {
|
||||
assert(limit >= MIN_PAGENO - MDBX_ENABLE_REFUND);
|
||||
if (likely(MDBX_PNL_GETSIZE(pnl))) {
|
||||
if (unlikely(MDBX_PNL_GETSIZE(pnl) > PAGELIST_LIMIT))
|
||||
@@ -146,8 +135,7 @@ __hot __noinline MDBX_INTERNAL bool pnl_check(const const_pnl_t pnl,
|
||||
if (unlikely(MDBX_PNL_MOST(pnl) >= limit))
|
||||
return false;
|
||||
|
||||
if ((!MDBX_DISABLE_VALIDATION || AUDIT_ENABLED()) &&
|
||||
likely(MDBX_PNL_GETSIZE(pnl) > 1)) {
|
||||
if ((!MDBX_DISABLE_VALIDATION || AUDIT_ENABLED()) && likely(MDBX_PNL_GETSIZE(pnl) > 1)) {
|
||||
const pgno_t *scan = MDBX_PNL_BEGIN(pnl);
|
||||
const pgno_t *const end = MDBX_PNL_END(pnl);
|
||||
pgno_t prev = *scan++;
|
||||
@@ -161,10 +149,9 @@ __hot __noinline MDBX_INTERNAL bool pnl_check(const const_pnl_t pnl,
|
||||
return true;
|
||||
}
|
||||
|
||||
static __always_inline void
|
||||
pnl_merge_inner(pgno_t *__restrict dst, const pgno_t *__restrict src_a,
|
||||
const pgno_t *__restrict src_b,
|
||||
const pgno_t *__restrict const src_b_detent) {
|
||||
static __always_inline void pnl_merge_inner(pgno_t *__restrict dst, const pgno_t *__restrict src_a,
|
||||
const pgno_t *__restrict src_b,
|
||||
const pgno_t *__restrict const src_b_detent) {
|
||||
do {
|
||||
#if MDBX_HAVE_CMOV
|
||||
const bool flag = MDBX_PNL_ORDERED(*src_b, *src_a);
|
||||
@@ -203,14 +190,11 @@ __hot MDBX_INTERNAL size_t pnl_merge(pnl_t dst, const pnl_t src) {
|
||||
total += src_len;
|
||||
if (!MDBX_DEBUG && total < (MDBX_HAVE_CMOV ? 21 : 12))
|
||||
goto avoid_call_libc_for_short_cases;
|
||||
if (dst_len == 0 ||
|
||||
MDBX_PNL_ORDERED(MDBX_PNL_LAST(dst), MDBX_PNL_FIRST(src)))
|
||||
if (dst_len == 0 || MDBX_PNL_ORDERED(MDBX_PNL_LAST(dst), MDBX_PNL_FIRST(src)))
|
||||
memcpy(MDBX_PNL_END(dst), MDBX_PNL_BEGIN(src), src_len * sizeof(pgno_t));
|
||||
else if (MDBX_PNL_ORDERED(MDBX_PNL_LAST(src), MDBX_PNL_FIRST(dst))) {
|
||||
memmove(MDBX_PNL_BEGIN(dst) + src_len, MDBX_PNL_BEGIN(dst),
|
||||
dst_len * sizeof(pgno_t));
|
||||
memcpy(MDBX_PNL_BEGIN(dst), MDBX_PNL_BEGIN(src),
|
||||
src_len * sizeof(pgno_t));
|
||||
memmove(MDBX_PNL_BEGIN(dst) + src_len, MDBX_PNL_BEGIN(dst), dst_len * sizeof(pgno_t));
|
||||
memcpy(MDBX_PNL_BEGIN(dst), MDBX_PNL_BEGIN(src), src_len * sizeof(pgno_t));
|
||||
} else {
|
||||
avoid_call_libc_for_short_cases:
|
||||
dst[0] = /* the detent */ (MDBX_PNL_ASCENDING ? 0 : P_INVALID);
|
||||
@@ -227,8 +211,7 @@ __hot MDBX_INTERNAL size_t pnl_merge(pnl_t dst, const pnl_t src) {
|
||||
#else
|
||||
#define MDBX_PNL_EXTRACT_KEY(ptr) (P_INVALID - *(ptr))
|
||||
#endif
|
||||
RADIXSORT_IMPL(pgno, pgno_t, MDBX_PNL_EXTRACT_KEY,
|
||||
MDBX_PNL_PREALLOC_FOR_RADIXSORT, 0)
|
||||
RADIXSORT_IMPL(pgno, pgno_t, MDBX_PNL_EXTRACT_KEY, MDBX_PNL_PREALLOC_FOR_RADIXSORT, 0)
|
||||
|
||||
SORT_IMPL(pgno_sort, false, pgno_t, MDBX_PNL_ORDERED)
|
||||
|
||||
@@ -240,8 +223,7 @@ __hot __noinline MDBX_INTERNAL void pnl_sort_nochk(pnl_t pnl) {
|
||||
|
||||
SEARCH_IMPL(pgno_bsearch, pgno_t, pgno_t, MDBX_PNL_ORDERED)
|
||||
|
||||
__hot __noinline MDBX_INTERNAL size_t pnl_search_nochk(const pnl_t pnl,
|
||||
pgno_t pgno) {
|
||||
__hot __noinline MDBX_INTERNAL size_t pnl_search_nochk(const pnl_t pnl, pgno_t pgno) {
|
||||
const pgno_t *begin = MDBX_PNL_BEGIN(pnl);
|
||||
const pgno_t *it = pgno_bsearch(begin, MDBX_PNL_GETSIZE(pnl), pgno);
|
||||
const pgno_t *end = begin + MDBX_PNL_GETSIZE(pnl);
|
||||
|
Reference in New Issue
Block a user