MCPcopy Create free account
hub / github.com/coreutils/coreutils / compare

Function compare

src/sort.c:2983–3023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2981 depending on whether A compares less than, equal to, or greater than B. */
2982
2983static int
2984compare (struct line const *a, struct line const *b)
2985{
2986 int diff;
2987 size_t alen, blen;
2988
2989 /* First try to compare on the specified keys (if any).
2990 The only two cases with no key at all are unadorned sort,
2991 and unadorned sort -r. */
2992 if (keylist)
2993 {
2994 diff = keycompare (a, b);
2995 if (diff || unique || stable)
2996 return diff;
2997 }
2998
2999 /* If the keys all compare equal (or no keys were specified)
3000 fall through to the default comparison. */
3001 alen = a->length - 1, blen = b->length - 1;
3002
3003 if (alen == 0)
3004 diff = - NONZERO (blen);
3005 else if (blen == 0)
3006 diff = 1;
3007 else if (hard_LC_COLLATE)
3008 {
3009 /* xmemcoll0 is a performance enhancement as
3010 it will not unconditionally write '\0' after the
3011 passed in buffers, which was seen to give around
3012 a 3% increase in performance for short lines. */
3013 diff = xmemcoll0 (a->text, alen + 1, b->text, blen + 1);
3014 }
3015 else
3016 {
3017 diff = memcmp (a->text, b->text, MIN (alen, blen));
3018 if (!diff)
3019 diff = _GL_CMP (alen, blen);
3020 }
3021
3022 return diff_reversed (diff, reverse);
3023}
3024
3025/* Write LINE to output stream FP; the output file's name is
3026 OUTPUT_FILE if OUTPUT_FILE is non-null, and is the standard output

Callers 8

heapify_downFunction · 0.85
heapify_upFunction · 0.85
checkFunction · 0.85
mergefpsFunction · 0.85
mergelinesFunction · 0.85
sequential_sortFunction · 0.85
write_uniqueFunction · 0.85
mergelines_nodeFunction · 0.85

Calls 2

keycompareFunction · 0.85
diff_reversedFunction · 0.85

Tested by

no test coverage detected