There can be a good intellectual challenge in refactoring code like that to be both efficient and readable (although at some extremes, and depending on the programming language, perhaps there'll be conflict between those two goals).
All the better if that refactoring is in a FOSS application/library to save other people the repeat effort (and potentially gather further improvements).