Re:A fun optimization trick from rsync
by usefulcat on Sunday October 28, 2018 @10:20PM
(#18324530)
An interesting trick, but it seems like there would be a simpler way, like having set_the_mtime be a function pointer. Initially it would point to an implementation that figures out which method works and sets the function pointer to point to a particular implementation.
[ Parent
| on HN ]
Sounds really clever, but also has the potential to be really opaque and confusing. On the other hand, the trick in the article is quite verbose.
Can be tricky balancing terseness with readability.
> has the potential to be really opaque and confusing
Yes, but.. compared to switch and preprocessor hacks described in the article? Granted it's subjective but I'd find a function pointer that's assigned to once to be way easier to comprehend.
Yeah, I think both methods are somewhat opaque, and the one described here is opaque + hacky. I wouldn't let this through code review.
I would say that this switch hack is lightyears more "clever" (that is, opaque and confusing) than a simple function pointer.
It's more inliner-friendly this way though.
No. Compiler can't assume value of switch_step at compile time, so it would have to inline the whole horrid thing every single time.
no guarantee the signatures are the same on all functions, can't use a fp
In that case wrapper functions can be created where needed to normalize the signatures.
Creating signature normalization wrappers, which contain superset of all the function parameters really complicates the code a lot.
It's like trying to push anything and everything through a little hole.
Re:A fun optimization trick from rsync
by kochthesecond on Monday October 29, 2018 @12:36PM
(#18328833)
Have you heard of our Lord and savior, the single method interface?