]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/BaseSortLib/BaseSortLib.c
zero memory allocation.
[mirror_edk2.git] / ShellPkg / Library / BaseSortLib / BaseSortLib.c
index eaee544d3d61ce8a56fb7d801465d60cb08f0cbd..2a3058d3caeb7a35494d9a2229463e615066cd3c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Library used for sorting routines.\r
 \r
-  Copyright (c) 2009-2010, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -62,7 +62,7 @@ QuickSortWorker (
 \r
   if ( Count < 2\r
     || ElementSize  < 1\r
-    ){\r
+   ){\r
     return;\r
   }\r
 \r
@@ -80,7 +80,7 @@ QuickSortWorker (
   for ( LoopCount = 0\r
       ; LoopCount < Count -1\r
       ; LoopCount++\r
-      ){\r
+     ){\r
     //\r
     // if the element is less than the pivot\r
     //\r
@@ -109,20 +109,23 @@ QuickSortWorker (
   // Now recurse on 2 paritial lists.  neither of these will have the 'pivot' element\r
   // IE list is sorted left half, pivot element, sorted right half...\r
   //\r
-  QuickSortWorker(\r
-    BufferToSort,\r
-    NextSwapLocation,\r
-    ElementSize,\r
-    CompareFunction,\r
-    Buffer);\r
-\r
-  QuickSortWorker(\r
-    (UINT8 *)BufferToSort + (NextSwapLocation+1) * ElementSize,\r
-    Count - NextSwapLocation - 1,\r
-    ElementSize,\r
-    CompareFunction,\r
-    Buffer);\r
+  if (NextSwapLocation >= 2) {\r
+    QuickSortWorker(\r
+      BufferToSort,\r
+      NextSwapLocation,\r
+      ElementSize,\r
+      CompareFunction,\r
+      Buffer);\r
+  }\r
 \r
+  if ((Count - NextSwapLocation - 1) >= 2) {\r
+    QuickSortWorker(\r
+      (UINT8 *)BufferToSort + (NextSwapLocation+1) * ElementSize,\r
+      Count - NextSwapLocation - 1,\r
+      ElementSize,\r
+      CompareFunction,\r
+      Buffer);\r
+  }\r
   return;\r
 }\r
 /**\r
@@ -157,7 +160,7 @@ PerformQuickSort (
   ASSERT(BufferToSort     != NULL);\r
   ASSERT(CompareFunction  != NULL);\r
 \r
-  Buffer = AllocatePool(ElementSize);\r
+  Buffer = AllocateZeroPool(ElementSize);\r
   ASSERT(Buffer != NULL);\r
 \r
   QuickSortWorker(\r
@@ -174,9 +177,13 @@ PerformQuickSort (
 /**\r
   Not supported in Base version.\r
 \r
+  @param[in] Buffer1  Ignored.\r
+  @param[in] Buffer2  Ignored.\r
+\r
   ASSERT and return 0.\r
 **/\r
 INTN\r
+EFIAPI\r
 DevicePathCompare (\r
   IN  CONST VOID             *Buffer1,\r
   IN  CONST VOID             *Buffer2\r
@@ -208,3 +215,25 @@ StringNoCaseCompare (
 }\r
 \r
 \r
+/**\r
+  Function to compare 2 strings.\r
+\r
+  @param[in] Buffer1            Pointer to String to compare (CHAR16**).\r
+  @param[in] Buffer2            Pointer to second String to compare (CHAR16**).\r
+\r
+  @retval 0                     Buffer1 equal to Buffer2.\r
+  @return < 0                   Buffer1 is less than Buffer2.\r
+  @return > 0                   Buffer1 is greater than Buffer2.\r
+**/\r
+INTN\r
+EFIAPI\r
+StringCompare (\r
+  IN  CONST VOID                *Buffer1,\r
+  IN  CONST VOID                *Buffer2\r
+  )\r
+{\r
+  ASSERT(FALSE);\r
+  return 0;\r
+}\r
+\r
+\r