>>51080690>Nothing stopping you from writing a better sorting function, kid.the C language syntax stops you
the only way to pass a function (e.g. a comparator) in C is to take the address of that function as a void*. if you take the address of a function, then it can't be inlined, since it has to have an address. so the only way that qsort will inline its comparator is if qsort is itself inline and can ellide the function pointer. qsort is a big function, so this is likely to not happen
std::sort instantiates a unique function body for each comparator. even if the function body is not inline, the comparator is known and will definitely be inlined if it is short. this makes anywhere from a 2-10x performance difference on reasonably large containers
this isn't a sort problem, it's a problem with all 2nd-order fxns. it's a really basic fucking problem. people will say dumb shit like "reimplement sort for each comparator," as if a high-performance sort isn't a legitimately Hard Problem worthy of a research paper