3 ms·
I love small and simple, I love self-contained. But then I got to GetMimeType, where he wrote his own binary search code instead of calling the C library to do
by wrs 15y ago
I love small and simple, I love self-contained. But then I got to GetMimeType, where he wrote his own binary search code instead of calling the C library to do it.
Though it sounds simple, binary search is a minefield of edge cases and I've seen textbooks that do it wrong.
So when I read the GetMimeType function, I didn't think "how nice and simple"...I thought "Hmm, I bet that doesn't work."
- dchest 15y agoThose 11 lines of reimplemented bsearch are correct.
- wrs 15y agoOh, I'm sure they are, purely based on who wrote them...but in any ordinary codebase I'd toss this code out in a second and replace it with a library call. It's just not worth the effort to decide whether it's correct -- like not bothering to bend over to pick up a lost penny.