MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / compareStringObjectsWithFlags

Function compareStringObjectsWithFlags

src/object.cpp:590–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588#define REDIS_COMPARE_COLL (1<<1)
589
590int compareStringObjectsWithFlags(robj *a, robj *b, int flags) {
591 serverAssertWithInfo(NULL,a,a->type == OBJ_STRING && b->type == OBJ_STRING);
592 char bufa[128], bufb[128], *astr, *bstr;
593 size_t alen, blen, minlen;
594
595 if (a == b) return 0;
596 if (sdsEncodedObject(a)) {
597 astr = szFromObj(a);
598 alen = sdslen(astr);
599 } else {
600 alen = ll2string(bufa,sizeof(bufa),(long) ptrFromObj(a));
601 astr = bufa;
602 }
603 if (sdsEncodedObject(b)) {
604 bstr = szFromObj(b);
605 blen = sdslen(bstr);
606 } else {
607 blen = ll2string(bufb,sizeof(bufb),(long) ptrFromObj(b));
608 bstr = bufb;
609 }
610 if (flags & REDIS_COMPARE_COLL) {
611 return strcoll(astr,bstr);
612 } else {
613 int cmp;
614
615 minlen = (alen < blen) ? alen : blen;
616 cmp = memcmp(astr,bstr,minlen);
617 if (cmp == 0) return alen-blen;
618 return cmp;
619 }
620}
621
622/* Wrapper for compareStringObjectsWithFlags() using binary comparison. */
623int compareStringObjects(robj *a, robj *b) {

Callers 2

compareStringObjectsFunction · 0.85
collateStringObjectsFunction · 0.85

Calls 4

szFromObjFunction · 0.85
sdslenFunction · 0.85
ll2stringFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected