Added inlined version of apple's sort.