MCPcopy Create free account
hub / github.com/F-Stack/f-stack / compareStringObjectsWithFlags

Function compareStringObjectsWithFlags

app/redis-6.2.6/src/object.c:548–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546#define REDIS_COMPARE_COLL (1<<1)
547
548int compareStringObjectsWithFlags(robj *a, robj *b, int flags) {
549 serverAssertWithInfo(NULL,a,a->type == OBJ_STRING && b->type == OBJ_STRING);
550 char bufa[128], bufb[128], *astr, *bstr;
551 size_t alen, blen, minlen;
552
553 if (a == b) return 0;
554 if (sdsEncodedObject(a)) {
555 astr = a->ptr;
556 alen = sdslen(astr);
557 } else {
558 alen = ll2string(bufa,sizeof(bufa),(long) a->ptr);
559 astr = bufa;
560 }
561 if (sdsEncodedObject(b)) {
562 bstr = b->ptr;
563 blen = sdslen(bstr);
564 } else {
565 blen = ll2string(bufb,sizeof(bufb),(long) b->ptr);
566 bstr = bufb;
567 }
568 if (flags & REDIS_COMPARE_COLL) {
569 return strcoll(astr,bstr);
570 } else {
571 int cmp;
572
573 minlen = (alen < blen) ? alen : blen;
574 cmp = memcmp(astr,bstr,minlen);
575 if (cmp == 0) return alen-blen;
576 return cmp;
577 }
578}
579
580/* Wrapper for compareStringObjectsWithFlags() using binary comparison. */
581int compareStringObjects(robj *a, robj *b) {

Callers 2

compareStringObjectsFunction · 0.85
collateStringObjectsFunction · 0.85

Calls 2

sdslenFunction · 0.85
ll2stringFunction · 0.85

Tested by

no test coverage detected