| 546 | #define REDIS_COMPARE_COLL (1<<1) |
| 547 | |
| 548 | int 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. */ |
| 581 | int compareStringObjects(robj *a, robj *b) { |
no test coverage detected