mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
branches/zip: Cleanup suggested by Osku.
ut_is_2pow(): New function for testing if a number is zero or a power of two. Use this function instead of bitwise arithmetics or ut_2_power_up() where possible.
This commit is contained in:
parent
8378c349e9
commit
5837f75150
10 changed files with 36 additions and 16 deletions
|
@ -1273,7 +1273,7 @@ fsp_fill_free_list(
|
|||
limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES, mtr);
|
||||
|
||||
zip_size = mach_read_from_4(FSP_PAGE_ZIP_SIZE + header);
|
||||
ut_a(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_a(ut_is_2pow(zip_size));
|
||||
ut_a(zip_size <= UNIV_PAGE_SIZE);
|
||||
ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
||||
|
||||
|
@ -2842,7 +2842,7 @@ fsp_reserve_free_extents(
|
|||
|
||||
space_header = fsp_get_space_header(space, mtr);
|
||||
zip_size = mach_read_from_4(FSP_PAGE_ZIP_SIZE + space_header);
|
||||
ut_a(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_a(ut_is_2pow(zip_size));
|
||||
ut_a(zip_size <= UNIV_PAGE_SIZE);
|
||||
ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
||||
try_again:
|
||||
|
@ -3747,7 +3747,7 @@ fsp_validate(
|
|||
header = fsp_get_space_header(space, &mtr);
|
||||
|
||||
zip_size = mach_read_from_4(FSP_PAGE_ZIP_SIZE + header);
|
||||
ut_a(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_a(ut_is_2pow(zip_size));
|
||||
ut_a(zip_size <= UNIV_PAGE_SIZE);
|
||||
ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ hash_create_mutexes(
|
|||
{
|
||||
ulint i;
|
||||
|
||||
ut_a(n_mutexes == ut_2_power_up(n_mutexes));
|
||||
ut_a(n_mutexes > 0 && ut_is_2pow(n_mutexes));
|
||||
|
||||
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
|
||||
|
||||
|
|
|
@ -572,7 +572,7 @@ ibuf_bitmap_page_init(
|
|||
{
|
||||
ulint byte_offset;
|
||||
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
fil_page_set_type(page, FIL_PAGE_IBUF_BITMAP);
|
||||
|
||||
|
@ -639,7 +639,7 @@ ibuf_bitmap_page_get_bits(
|
|||
#if IBUF_BITS_PER_PAGE % 2
|
||||
# error "IBUF_BITS_PER_PAGE % 2 != 0"
|
||||
#endif
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
ut_ad(mtr_memo_contains(mtr, buf_block_align(page),
|
||||
MTR_MEMO_PAGE_X_FIX));
|
||||
|
||||
|
@ -691,7 +691,7 @@ ibuf_bitmap_page_set_bits(
|
|||
#if IBUF_BITS_PER_PAGE % 2
|
||||
# error "IBUF_BITS_PER_PAGE % 2 != 0"
|
||||
#endif
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
ut_ad(mtr_memo_contains(mtr, buf_block_align(page),
|
||||
MTR_MEMO_PAGE_X_FIX));
|
||||
#ifdef UNIV_IBUF_DEBUG
|
||||
|
@ -741,7 +741,7 @@ ibuf_bitmap_page_no_calc(
|
|||
0 for uncompressed pages */
|
||||
ulint page_no) /* in: tablespace page number */
|
||||
{
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
if (!zip_size) {
|
||||
return(FSP_IBUF_BITMAP_OFFSET
|
||||
|
|
|
@ -17,7 +17,7 @@ fsp_descr_page(
|
|||
0 for uncompressed pages */
|
||||
ulint page_no)/* in: page number */
|
||||
{
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
if (!zip_size) {
|
||||
return(UNIV_UNLIKELY((page_no & (UNIV_PAGE_SIZE - 1))
|
||||
|
|
|
@ -116,7 +116,7 @@ ibuf_bitmap_page(
|
|||
0 for uncompressed pages */
|
||||
ulint page_no)/* in: page number */
|
||||
{
|
||||
ut_ad(!(zip_size & (zip_size - 1))); /* must be a power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
if (!zip_size) {
|
||||
return(UNIV_UNLIKELY((page_no & (UNIV_PAGE_SIZE - 1))
|
||||
|
|
|
@ -132,7 +132,7 @@ page_zip_simple_validate(
|
|||
{
|
||||
ut_ad(page_zip);
|
||||
ut_ad(page_zip->data);
|
||||
ut_ad(!(page_zip->size & (page_zip->size - 1))); /* power of 2 */
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
ut_ad(page_zip->size <= UNIV_PAGE_SIZE);
|
||||
ut_ad(page_zip->size > PAGE_DATA + PAGE_ZIP_DIR_SLOT_SIZE);
|
||||
ut_ad(page_zip->m_start <= page_zip->m_end);
|
||||
|
|
|
@ -273,7 +273,7 @@ ut_calc_align(
|
|||
ulint align_no) /* in: align by this number */
|
||||
{
|
||||
ut_ad(align_no > 0);
|
||||
ut_ad(((align_no - 1) & align_no) == 0);
|
||||
ut_ad(ut_is_2pow(align_no));
|
||||
|
||||
return((n + align_no - 1) & ~(align_no - 1));
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ ut_calc_align_down(
|
|||
ulint align_no) /* in: align by this number */
|
||||
{
|
||||
ut_ad(align_no > 0);
|
||||
ut_ad(((align_no - 1) & align_no) == 0);
|
||||
ut_ad(ut_is_2pow(align_no));
|
||||
|
||||
return(n & ~(align_no - 1));
|
||||
}
|
||||
|
|
|
@ -79,6 +79,14 @@ ut_pair_cmp(
|
|||
ulint b1, /* in: more significant part of second pair */
|
||||
ulint b2); /* in: less significant part of second pair */
|
||||
/*****************************************************************
|
||||
Determines if a number is zero or a power of two.
|
||||
This function is used in assertions or assertion-like tests. */
|
||||
UNIV_INLINE
|
||||
ibool
|
||||
ut_is_2pow(
|
||||
/*=======*/ /* out: TRUE if zero or a power of 2 */
|
||||
ulint n); /* in: number to be tested */
|
||||
/*****************************************************************
|
||||
Calculates fast the remainder when divided by a power of two. */
|
||||
UNIV_INLINE
|
||||
ulint
|
||||
|
|
|
@ -101,6 +101,18 @@ ut_pair_cmp(
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Determines if a number is zero or a power of two.
|
||||
This function is used in assertions or assertion-like tests. */
|
||||
UNIV_INLINE
|
||||
ibool
|
||||
ut_is_2pow(
|
||||
/*=======*/ /* out: TRUE if zero or a power of 2 */
|
||||
ulint n) /* in: number to be tested */
|
||||
{
|
||||
return(UNIV_LIKELY(!(n & (n - 1))));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Calculates fast the remainder when divided by a power of two. */
|
||||
UNIV_INLINE
|
||||
|
@ -110,7 +122,7 @@ ut_2pow_remainder(
|
|||
ulint n, /* in: number to be divided */
|
||||
ulint m) /* in: divisor; power of 2 */
|
||||
{
|
||||
ut_ad(0x80000000UL % m == 0);
|
||||
ut_ad(ut_is_2pow(m));
|
||||
|
||||
return(n & (m - 1));
|
||||
}
|
||||
|
@ -125,7 +137,7 @@ ut_2pow_round(
|
|||
ulint n, /* in: number to be rounded */
|
||||
ulint m) /* in: divisor; power of 2 */
|
||||
{
|
||||
ut_ad(0x80000000UL % m == 0);
|
||||
ut_ad(ut_is_2pow(m));
|
||||
|
||||
return(n & ~(m - 1));
|
||||
}
|
||||
|
|
|
@ -496,7 +496,7 @@ mem_area_free(
|
|||
|
||||
next_size = mem_area_get_size(
|
||||
(mem_area_t*)(((byte*)area) + size));
|
||||
if (ut_2_power_up(next_size) != next_size) {
|
||||
if (UNIV_UNLIKELY(!next_size || !ut_is_2pow(next_size))) {
|
||||
fprintf(stderr,
|
||||
"InnoDB: Error: Memory area size %lu, next area size %lu not a power of 2!\n"
|
||||
"InnoDB: Possibly a memory overrun of the buffer being freed here.\n",
|
||||
|
|
Loading…
Reference in a new issue