* Apply a sort comparator function and return a 3-way comparison result. * This takes care of handling reverse-sort and NULLs-ordering properly. */
| 197 | * This takes care of handling reverse-sort and NULLs-ordering properly. |
| 198 | */ |
| 199 | static inline int |
| 200 | ApplySortComparator(Datum datum1, bool isNull1, |
| 201 | Datum datum2, bool isNull2, |
| 202 | SortSupport ssup) |
| 203 | { |
| 204 | int compare; |
| 205 | |
| 206 | if (isNull1) |
| 207 | { |
| 208 | if (isNull2) |
| 209 | compare = 0; /* NULL "=" NULL */ |
| 210 | else if (ssup->ssup_nulls_first) |
| 211 | compare = -1; /* NULL "<" NOT_NULL */ |
| 212 | else |
| 213 | compare = 1; /* NULL ">" NOT_NULL */ |
| 214 | } |
| 215 | else if (isNull2) |
| 216 | { |
| 217 | if (ssup->ssup_nulls_first) |
| 218 | compare = 1; /* NOT_NULL ">" NULL */ |
| 219 | else |
| 220 | compare = -1; /* NOT_NULL "<" NULL */ |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | compare = ssup->comparator(datum1, datum2, ssup); |
| 225 | if (ssup->ssup_reverse) |
| 226 | INVERT_COMPARE_RESULT(compare); |
| 227 | } |
| 228 | |
| 229 | return compare; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Apply a sort comparator function and return a 3-way comparison using full, |
no outgoing calls
no test coverage detected