nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot()

Started by Chao Li10 months ago3 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi Hackers,

I noticed this while reviewing [1]/messages/by-id/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff. _bt_gettrueroot() performs the same
metapage checks as _bt_getmeta(), so using _bt_getmeta() here removes the
duplicated code.

Build passed without warning and "make check" passed.

[1]: /messages/by-id/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff
/messages/by-id/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

v1-0001-nbtree-deduplicate-metapage-sanity-checks-in-_bt_.patchapplication/octet-stream; name=v1-0001-nbtree-deduplicate-metapage-sanity-checks-in-_bt_.patchDownload+1-22
#2Neil Chen
carpenter.nail.cz@gmail.com
In reply to: Chao Li (#1)
Re: nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot()

Hi Chao,

On Thu, Jan 15, 2026 at 4:11 PM Chao Li <li.evan.chao@gmail.com> wrote:

I noticed this while reviewing [1]. _bt_gettrueroot() performs the same
metapage checks as _bt_getmeta(), so using _bt_getmeta() here removes the
duplicated code.

It looks good to me. These two code snippets are exactly identical,
so removing the redundant code is reasonable.

As can be seen from the contextual comments, this is not a
performance-critical path either,
so we don’t need to worry about the performance overhead caused by function
calls.

I also checked the changes made in commit dd299df, which essentially does
the same thing for the function _bt_getrootheight.

#3Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Neil Chen (#2)
Re: nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot()

On 16/01/2026 10:09, Neil Chen wrote:

Hi Chao,

On Thu, Jan 15, 2026 at 4:11 PM Chao Li <li.evan.chao@gmail.com
<mailto:li.evan.chao@gmail.com>> wrote:

I noticed this while reviewing [1]. _bt_gettrueroot() performs the
same metapage checks as _bt_getmeta(), so using _bt_getmeta() here
removes the duplicated code.

It looks good to me. These two code snippets are exactly identical,
so removing the redundant code is reasonable.

As can be seen from the contextual comments, this is not a performance-
critical path either,
so we don’t need to worry about the performance overhead caused by
function calls.

I also checked the changes made in commit dd299df, which essentially
does the same thing for the function _bt_getrootheight.

Ok, committed.

- Heikki