Reorder a couple of operations in inplace_merge so that we can meet the complexity guidelines mandated by the standard. References PR22427

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@227808 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/algorithm b/include/algorithm
index 02cbc81..a179acf 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -4407,6 +4407,9 @@
         // if __middle == __last, we're done
         if (__len2 == 0)
             return;
+        if (__len1 <= __buff_size || __len2 <= __buff_size)
+            return __buffered_inplace_merge<_Compare>
+                   (__first, __middle, __last, __comp, __len1, __len2, __buff);
         // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
         for (; true; ++__first, (void) --__len1)
         {
@@ -4415,11 +4418,6 @@
             if (__comp(*__middle, *__first))
                 break;
         }
-        if (__len1 <= __buff_size || __len2 <= __buff_size)
-        {
-            __buffered_inplace_merge<_Compare>(__first, __middle, __last, __comp, __len1, __len2, __buff);
-            return;
-        }
         // __first < __middle < __last
         // *__first > *__middle
         // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that