Basically, it decides whether the array is short (8 elements) and does an insertion sort if that is the case.

Otherwise, it takes the middle element as median. Original comment from the source code:

/* First we pick a partititioning element. The efficiency of the

algorithm demands that we find one that is approximately the

median of the values, but also that we select one fast. Using

the first one produces bad performace if the array is already

sorted, so we use the middle one, which would require a very

wierdly arranged array for worst case performance. Testing shows

that a median-of-three algorithm does not, in general, increase

performance. */