diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-19 07:52:35 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-19 15:09:13 +0200 |
commit | a66eebf57c212363f9f430a4c8c9a4f3ddf57cfb (patch) | |
tree | 0c7e48ae2bed8f3dbba1b43eee786f045f4ee2cd /storage/maria/ma_loghandler.c | |
parent | 6960e9ed24dbdab587730cdceab1f29bcdd6d52a (diff) | |
download | mariadb-git-a66eebf57c212363f9f430a4c8c9a4f3ddf57cfb.tar.gz |
MDEV-21981 Replace arithmetic + with bitwise OR when possible
Several macros such as sint2korr() and uint4korr() are using the
arithmetic + operator while a bitwise or operator would suffice.
GCC 5 and clang 5 and later can detect patterns consisting of
bitwise or and shifts by multiples of 8 bits, such as those used
in the InnoDB function mach_read_from_4(). They actually translate
that verbose low-level code into high-level machine language
(i486 bswap instruction or fused into the Haswell movbe instruction).
We should do the same for MariaDB Server code that is outside InnoDB.
Note: The Microsoft C compiler is lacking this optimization.
There, we might consider using _byteswap_ushort(), _byteswap_ulong(),
_byteswap_uint64(). But, those would lead to unaligned reads, which are
bad for reasons stated in MDEV-20277. Besides, outside InnoDB,
most data is already being stored in the native little-endian format
of that compiler.
Diffstat (limited to 'storage/maria/ma_loghandler.c')
-rw-r--r-- | storage/maria/ma_loghandler.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index 1d5bfba182d..9fe746a167b 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -1,4 +1,5 @@ /* Copyright (C) 2007 MySQL AB & Sanja Belkin. 2010 Monty Program Ab. + Copyright (c) 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -5440,15 +5441,15 @@ static uchar *translog_get_LSN_from_diff(LSN base_lsn, uchar *src, uchar *dst) src + 1 + LSN_STORE_SIZE)); DBUG_RETURN(src + 1 + LSN_STORE_SIZE); } - rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 8) + *((uint8*)src)); + rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 8) | *((uint8*)src)); break; case 1: diff= uint2korr(src); - rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 16) + diff); + rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 16) | diff); break; case 2: diff= uint3korr(src); - rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 24) + diff); + rec_offset= LSN_OFFSET(base_lsn) - ((first_byte << 24) | diff); break; case 3: { |