• antirez's avatar
    SDS: improve sdsRemoveFreeSpace() to avoid useless data copy. · 34d5804d
    antirez authored
    Since SDS v2, we no longer have a single header, so the function to
    rewrite the SDS in terms of the minimum space required, instead of just
    using realloc() and let the underlying allocator decide what to do,
    was doing an allocation + copy every time the minimum possible header
    needed to represent the string was different than the current one.
    This could be often a bit wasteful, because if we go, for instance, from
    the 32 bit fields header to the 16 bit fields header, the overhead of
    the header is normally very small. With this commit we call realloc
    instead, unless the change in header size is very significant in relation
    to the string length.
    34d5804d
sds.c 39.5 KB