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

Function lpGet

app/redis-6.2.6/src/listpack.c:551–630  ·  view source on GitHub ↗

Return the listpack element pointed by 'p'. * * The function changes behavior depending on the passed 'intbuf' value. * Specifically, if 'intbuf' is NULL: * * If the element is internally encoded as an integer, the function returns * NULL and populates the integer value by reference in 'count'. Otherwise if * the element is encoded as a string a pointer to the string (pointing inside * the

Source from the content-addressed store, hash-verified

549 * in order to check the integrity of the listpack at load time is provided,
550 * check lpIsValid(). */
551unsigned char *lpGet(unsigned char *p, int64_t *count, unsigned char *intbuf) {
552 int64_t val;
553 uint64_t uval, negstart, negmax;
554
555 assert(p); /* assertion for valgrind (avoid NPD) */
556 if (LP_ENCODING_IS_7BIT_UINT(p[0])) {
557 negstart = UINT64_MAX; /* 7 bit ints are always positive. */
558 negmax = 0;
559 uval = p[0] & 0x7f;
560 } else if (LP_ENCODING_IS_6BIT_STR(p[0])) {
561 *count = LP_ENCODING_6BIT_STR_LEN(p);
562 return p+1;
563 } else if (LP_ENCODING_IS_13BIT_INT(p[0])) {
564 uval = ((p[0]&0x1f)<<8) | p[1];
565 negstart = (uint64_t)1<<12;
566 negmax = 8191;
567 } else if (LP_ENCODING_IS_16BIT_INT(p[0])) {
568 uval = (uint64_t)p[1] |
569 (uint64_t)p[2]<<8;
570 negstart = (uint64_t)1<<15;
571 negmax = UINT16_MAX;
572 } else if (LP_ENCODING_IS_24BIT_INT(p[0])) {
573 uval = (uint64_t)p[1] |
574 (uint64_t)p[2]<<8 |
575 (uint64_t)p[3]<<16;
576 negstart = (uint64_t)1<<23;
577 negmax = UINT32_MAX>>8;
578 } else if (LP_ENCODING_IS_32BIT_INT(p[0])) {
579 uval = (uint64_t)p[1] |
580 (uint64_t)p[2]<<8 |
581 (uint64_t)p[3]<<16 |
582 (uint64_t)p[4]<<24;
583 negstart = (uint64_t)1<<31;
584 negmax = UINT32_MAX;
585 } else if (LP_ENCODING_IS_64BIT_INT(p[0])) {
586 uval = (uint64_t)p[1] |
587 (uint64_t)p[2]<<8 |
588 (uint64_t)p[3]<<16 |
589 (uint64_t)p[4]<<24 |
590 (uint64_t)p[5]<<32 |
591 (uint64_t)p[6]<<40 |
592 (uint64_t)p[7]<<48 |
593 (uint64_t)p[8]<<56;
594 negstart = (uint64_t)1<<63;
595 negmax = UINT64_MAX;
596 } else if (LP_ENCODING_IS_12BIT_STR(p[0])) {
597 *count = LP_ENCODING_12BIT_STR_LEN(p);
598 return p+2;
599 } else if (LP_ENCODING_IS_32BIT_STR(p[0])) {
600 *count = LP_ENCODING_32BIT_STR_LEN(p);
601 return p+5;
602 } else {
603 uval = 12345678900000000ULL + p[0];
604 negstart = UINT64_MAX;
605 negmax = 0;
606 }
607
608 /* We reach this code path only for integer encodings.

Callers 4

lpGetIntegerIfValidFunction · 0.85
streamLogListpackContentFunction · 0.85
streamAppendItemFunction · 0.85
streamIteratorGetFieldFunction · 0.85

Calls 1

snprintfFunction · 0.85

Tested by

no test coverage detected