"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/listpack.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

listpack.c  (redis-6.2-rc3):listpack.c  (redis-6.2.0)
skipping to change at line 222 skipping to change at line 222
if (value != NULL) *value = -v; if (value != NULL) *value = -v;
} else { } else {
if (v > INT64_MAX) /* Overflow. */ if (v > INT64_MAX) /* Overflow. */
return 0; return 0;
if (value != NULL) *value = v; if (value != NULL) *value = v;
} }
return 1; return 1;
} }
/* Create a new, empty listpack. /* Create a new, empty listpack.
* On success the new listpack is returned, otherwise an error is returned. */ * On success the new listpack is returned, otherwise an error is returned.
unsigned char *lpNew(void) { * Pre-allocate at least `capacity` bytes of memory,
unsigned char *lp = lp_malloc(LP_HDR_SIZE+1); * over-allocated memory can be shrinked by `lpShrinkToFit`.
* */
unsigned char *lpNew(size_t capacity) {
unsigned char *lp = lp_malloc(capacity > LP_HDR_SIZE+1 ? capacity : LP_HDR_S
IZE+1);
if (lp == NULL) return NULL; if (lp == NULL) return NULL;
lpSetTotalBytes(lp,LP_HDR_SIZE+1); lpSetTotalBytes(lp,LP_HDR_SIZE+1);
lpSetNumElements(lp,0); lpSetNumElements(lp,0);
lp[LP_HDR_SIZE] = LP_EOF; lp[LP_HDR_SIZE] = LP_EOF;
return lp; return lp;
} }
/* Free the specified listpack. */ /* Free the specified listpack. */
void lpFree(unsigned char *lp) { void lpFree(unsigned char *lp) {
lp_free(lp); lp_free(lp);
} }
/* Shrink the memory to fit. */
unsigned char* lpShrinkToFit(unsigned char *lp) {
size_t size = lpGetTotalBytes(lp);
if (size < lp_malloc_size(lp)) {
return lp_realloc(lp, size);
} else {
return lp;
}
}
/* Given an element 'ele' of size 'size', determine if the element can be /* Given an element 'ele' of size 'size', determine if the element can be
* represented inside the listpack encoded as integer, and returns * represented inside the listpack encoded as integer, and returns
* LP_ENCODING_INT if so. Otherwise returns LP_ENCODING_STR if no integer * LP_ENCODING_INT if so. Otherwise returns LP_ENCODING_STR if no integer
* encoding is possible. * encoding is possible.
* *
* If the LP_ENCODING_INT is returned, the function stores the integer encoded * If the LP_ENCODING_INT is returned, the function stores the integer encoded
* representation of the element in the 'intenc' buffer. * representation of the element in the 'intenc' buffer.
* *
* Regardless of the returned encoding, 'enclen' is populated by reference to * Regardless of the returned encoding, 'enclen' is populated by reference to
* the number of bytes that the string or integer encoded element will require * the number of bytes that the string or integer encoded element will require
skipping to change at line 705 skipping to change at line 718
/* We now need to reallocate in order to make space or shrink the /* We now need to reallocate in order to make space or shrink the
* allocation (in case 'when' value is LP_REPLACE and the new element is * allocation (in case 'when' value is LP_REPLACE and the new element is
* smaller). However we do that before memmoving the memory to * smaller). However we do that before memmoving the memory to
* make room for the new element if the final allocation will get * make room for the new element if the final allocation will get
* larger, or we do it after if the final allocation will get smaller. */ * larger, or we do it after if the final allocation will get smaller. */
unsigned char *dst = lp + poff; /* May be updated after reallocation. */ unsigned char *dst = lp + poff; /* May be updated after reallocation. */
/* Realloc before: we need more room. */ /* Realloc before: we need more room. */
if (new_listpack_bytes > old_listpack_bytes) { if (new_listpack_bytes > old_listpack_bytes &&
new_listpack_bytes > lp_malloc_size(lp)) {
if ((lp = lp_realloc(lp,new_listpack_bytes)) == NULL) return NULL; if ((lp = lp_realloc(lp,new_listpack_bytes)) == NULL) return NULL;
dst = lp + poff; dst = lp + poff;
} }
/* Setup the listpack relocating the elements to make the exact room /* Setup the listpack relocating the elements to make the exact room
* we need to store the new one. */ * we need to store the new one. */
if (where == LP_BEFORE) { if (where == LP_BEFORE) {
memmove(dst+enclen+backlen_size,dst,old_listpack_bytes-poff); memmove(dst+enclen+backlen_size,dst,old_listpack_bytes-poff);
} else { /* LP_REPLACE. */ } else { /* LP_REPLACE. */
long lendiff = (enclen+backlen_size)-replaced_len; long lendiff = (enclen+backlen_size)-replaced_len;
 End of changes. 3 change blocks. 
4 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)