• Adam Simpkins's avatar
    update moveToFbString()'s handling of flags_ · d9298481
    Adam Simpkins authored
    Summary:
    Improve moveToFbString()'s code which determines if we actually have a
    buffer that was allocated with malloc().
    
    The old code simply checked if flags_ == kFlagExt.  This check is rather
    fragile, and relies on very specific behavior from the existing
    construction methods.  It also unnecessarily forced reallocation in some
    cases.
    
    This updates the code to have more specific checks for the flags and
    fields that actually matter.  In particular, even if we have an external
    buffer, if sharedInfo->freeFn is set then it is not managed by malloc().
    The old check happened to work because takeOwnership() was the only
    function that set set freeFn, and it also set kFlagFreeSharedInfo.
    
    This also improves the code so that it won't unnecessarily reallocate
    the buffer if kFlagMaybeShared is set but the buffer isn't really
    shared.  The code will also no longer unnecessarily reallocates the
    buffer just because kFlagFreeSharedInfo is set.
    
    Test Plan:
    Updated the moveToFbString() test to also test with buffers created
    using takeOwnership() and wrapBuffer().
    
    Reviewed By: davejwatson@fb.com
    
    FB internal diff: D1072304
    
    @override-unit-failures
    d9298481
IOBufTest.cpp 25.8 KB