2 Library used for sorting routines.
4 Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Protocol/UnicodeCollation.h>
12 #include <Protocol/DevicePath.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/MemoryAllocationLib.h>
19 #include <Library/SortLib.h>
20 #include <Library/DevicePathLib.h>
22 STATIC EFI_UNICODE_COLLATION_PROTOCOL
*mUnicodeCollation
= NULL
;
24 #define USL_FREE_NON_NULL(Pointer) \
26 if ((Pointer) != NULL) { \
27 FreePool((Pointer)); \
33 Function to perform a Quick Sort alogrithm on a buffer of comparable elements.
35 Each element must be equal sized.
37 if BufferToSort is NULL, then ASSERT.
38 if CompareFunction is NULL, then ASSERT.
40 if Count is < 2 then perform no action.
41 if Size is < 1 then perform no action.
43 @param[in, out] BufferToSort on call a Buffer of (possibly sorted) elements
44 on return a buffer of sorted elements
45 @param[in] Count the number of elements in the buffer to sort
46 @param[in] ElementSize Size of an element in bytes
47 @param[in] CompareFunction The function to call to perform the comparison
53 IN OUT VOID
*BufferToSort
,
55 IN CONST UINTN ElementSize
,
56 IN SORT_COMPARE CompareFunction
61 ASSERT (BufferToSort
!= NULL
);
62 ASSERT (CompareFunction
!= NULL
);
64 Buffer
= AllocateZeroPool (ElementSize
);
65 ASSERT (Buffer
!= NULL
);
80 Function to compare 2 device paths for use in QuickSort.
82 @param[in] Buffer1 pointer to Device Path poiner to compare
83 @param[in] Buffer2 pointer to second DevicePath pointer to compare
85 @retval 0 Buffer1 equal to Buffer2
86 @retval <0 Buffer1 is less than Buffer2
87 @retval >0 Buffer1 is greater than Buffer2
92 IN CONST VOID
*Buffer1
,
93 IN CONST VOID
*Buffer2
96 EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
;
97 EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
;
103 DevicePath1
= *(EFI_DEVICE_PATH_PROTOCOL
**)Buffer1
;
104 DevicePath2
= *(EFI_DEVICE_PATH_PROTOCOL
**)Buffer2
;
106 if (DevicePath1
== NULL
) {
107 if (DevicePath2
== NULL
) {
114 if (DevicePath2
== NULL
) {
118 if (mUnicodeCollation
== NULL
) {
119 Status
= gBS
->LocateProtocol (
120 &gEfiUnicodeCollation2ProtocolGuid
,
122 (VOID
**)&mUnicodeCollation
125 ASSERT_EFI_ERROR (Status
);
128 TextPath1
= ConvertDevicePathToText (
134 TextPath2
= ConvertDevicePathToText (
140 if (TextPath1
== NULL
) {
142 } else if (TextPath2
== NULL
) {
145 RetVal
= mUnicodeCollation
->StriColl (
152 USL_FREE_NON_NULL (TextPath1
);
153 USL_FREE_NON_NULL (TextPath2
);
159 Function to compare 2 strings without regard to case of the characters.
161 @param[in] Buffer1 Pointer to String to compare.
162 @param[in] Buffer2 Pointer to second String to compare.
164 @retval 0 Buffer1 equal to Buffer2.
165 @retval <0 Buffer1 is less than Buffer2.
166 @retval >0 Buffer1 is greater than Buffer2.
170 StringNoCaseCompare (
171 IN CONST VOID
*Buffer1
,
172 IN CONST VOID
*Buffer2
177 if (mUnicodeCollation
== NULL
) {
178 Status
= gBS
->LocateProtocol (
179 &gEfiUnicodeCollation2ProtocolGuid
,
181 (VOID
**)&mUnicodeCollation
184 ASSERT_EFI_ERROR (Status
);
187 return (mUnicodeCollation
->StriColl (
195 Function to compare 2 strings.
197 @param[in] Buffer1 Pointer to String to compare (CHAR16**).
198 @param[in] Buffer2 Pointer to second String to compare (CHAR16**).
200 @retval 0 Buffer1 equal to Buffer2.
201 @retval <0 Buffer1 is less than Buffer2.
202 @retval >0 Buffer1 is greater than Buffer2.
207 IN CONST VOID
*Buffer1
,
208 IN CONST VOID
*Buffer2