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
);
124 ASSERT_EFI_ERROR(Status
);
127 TextPath1
= ConvertDevicePathToText(
132 TextPath2
= ConvertDevicePathToText(
137 if (TextPath1
== NULL
) {
139 } else if (TextPath2
== NULL
) {
142 RetVal
= mUnicodeCollation
->StriColl(
148 USL_FREE_NON_NULL(TextPath1
);
149 USL_FREE_NON_NULL(TextPath2
);
155 Function to compare 2 strings without regard to case of the characters.
157 @param[in] Buffer1 Pointer to String to compare.
158 @param[in] Buffer2 Pointer to second String to compare.
160 @retval 0 Buffer1 equal to Buffer2.
161 @retval <0 Buffer1 is less than Buffer2.
162 @retval >0 Buffer1 is greater than Buffer2.
166 StringNoCaseCompare (
167 IN CONST VOID
*Buffer1
,
168 IN CONST VOID
*Buffer2
172 if (mUnicodeCollation
== NULL
) {
173 Status
= gBS
->LocateProtocol(
174 &gEfiUnicodeCollation2ProtocolGuid
,
176 (VOID
**)&mUnicodeCollation
);
178 ASSERT_EFI_ERROR(Status
);
181 return (mUnicodeCollation
->StriColl(
184 *(CHAR16
**)Buffer2
));
189 Function to compare 2 strings.
191 @param[in] Buffer1 Pointer to String to compare (CHAR16**).
192 @param[in] Buffer2 Pointer to second String to compare (CHAR16**).
194 @retval 0 Buffer1 equal to Buffer2.
195 @retval <0 Buffer1 is less than Buffer2.
196 @retval >0 Buffer1 is greater than Buffer2.
201 IN CONST VOID
*Buffer1
,
202 IN CONST VOID
*Buffer2
207 *(CHAR16
**)Buffer2
));