Browse Source

MDEV-7942: InnoDB: abuse of UNIV_LIKELY()/UNIV_UNLIKELY()

UNIV_LIKELY()/UNIV_UNLIKELY() hints are supposed to improve branch prediction.
Currently, they're expected to work only if cond evaluates to TRUE or FALSE.

However there're a few conditions that may evaluate to different values, e.g.:

page/page0zip.cc:		if (UNIV_LIKELY(c_stream->avail_in)) {
page/page0zip.cc:			if (UNIV_LIKELY(c_stream->avail_in)) {
dict/dict0mem.cc:		if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {

Fixed these conditions so that they evaluate TRUE/FALSE.
pull/62/head
Jan Lindström 11 years ago
parent
commit
58e8db2eb3
  1. 2
      storage/innobase/dict/dict0mem.cc
  2. 4
      storage/innobase/page/page0zip.cc
  3. 2
      storage/xtradb/dict/dict0mem.cc
  4. 4
      storage/xtradb/page/page0zip.cc

2
storage/innobase/dict/dict0mem.cc

@ -285,7 +285,7 @@ dict_mem_table_add_col(
if (UNIV_UNLIKELY(table->n_def == table->n_cols)) {
heap = table->heap;
}
if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
if (UNIV_LIKELY(i != 0) && UNIV_UNLIKELY(table->col_names == NULL)) {
/* All preceding column names are empty. */
char* s = static_cast<char*>(
mem_heap_zalloc(heap, table->n_def));

4
storage/innobase/page/page0zip.cc

@ -923,7 +923,7 @@ page_zip_compress_sec(
rec - REC_N_NEW_EXTRA_BYTES
- c_stream->next_in);
if (UNIV_LIKELY(c_stream->avail_in)) {
if (UNIV_LIKELY(c_stream->avail_in != 0)) {
UNIV_MEM_ASSERT_RW(c_stream->next_in,
c_stream->avail_in);
err = deflate(c_stream, Z_NO_FLUSH);
@ -1018,7 +1018,7 @@ page_zip_compress_clust_ext(
c_stream->avail_in = static_cast<uInt>(
src - c_stream->next_in);
if (UNIV_LIKELY(c_stream->avail_in)) {
if (UNIV_LIKELY(c_stream->avail_in != 0)) {
err = deflate(c_stream, Z_NO_FLUSH);
if (UNIV_UNLIKELY(err != Z_OK)) {

2
storage/xtradb/dict/dict0mem.cc

@ -301,7 +301,7 @@ dict_mem_table_add_col(
if (UNIV_UNLIKELY(table->n_def == table->n_cols)) {
heap = table->heap;
}
if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
if (UNIV_LIKELY(i != 0) && UNIV_UNLIKELY(table->col_names == NULL)) {
/* All preceding column names are empty. */
char* s = static_cast<char*>(
mem_heap_zalloc(heap, table->n_def));

4
storage/xtradb/page/page0zip.cc

@ -912,7 +912,7 @@ page_zip_compress_sec(
rec - REC_N_NEW_EXTRA_BYTES
- c_stream->next_in);
if (UNIV_LIKELY(c_stream->avail_in)) {
if (UNIV_LIKELY(c_stream->avail_in != 0)) {
UNIV_MEM_ASSERT_RW(c_stream->next_in,
c_stream->avail_in);
err = deflate(c_stream, Z_NO_FLUSH);
@ -1007,7 +1007,7 @@ page_zip_compress_clust_ext(
c_stream->avail_in = static_cast<uInt>(
src - c_stream->next_in);
if (UNIV_LIKELY(c_stream->avail_in)) {
if (UNIV_LIKELY(c_stream->avail_in != 0)) {
err = deflate(c_stream, Z_NO_FLUSH);
if (UNIV_UNLIKELY(err != Z_OK)) {

Loading…
Cancel
Save