Closed raphaelcohn closed 3 years ago
I believe these are optimized away in release mode, but please do let me know if you do find some that aren't.
Also, I would be very interested in hearing your results with likely
/unlikely
!
Closing as no longer relevant.
Whilst looking through some of the code in
NodePtr
, I observed a couple of possible minor optimizations; I haven't had the chance to test these and its possible they are optimized out in release mode, in any event.I found them whilst exploring whether
unlikely
/likely
hints might make a difference for a large tree.In
last_child()
andfirst_child()
there is a null guard. The same null guard is made insidenext()
andprevious()
; refactoting out the guarded code would allow one less if statement to be executed.There's a common pattern in
last_child()
andfirst_child()
which uses awhere
loop which checks for eitherleft()
or right being null before looping; it should be possible to replace this with a loop liketo avoid a second look up from memory. Given the recently accessed value is already going to be a register or cache, it's possibly moot. Similar code that checks
parent()
does the same innext()
/prev()
.