Skip to content
  • Jeff King's avatar
    tempfile: use list.h for linked list · 24d82185
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    The tempfile API keeps to-be-cleaned tempfiles in a
    singly-linked list and never removes items from the list.  A
    future patch would like to start removing items, but removal
    from a singly linked list is O(n), as we have to walk the
    list to find the predecessor element. This means that a
    process which takes "n" simultaneous lockfiles (for example,
    an atomic transaction on "n" refs) may end up quadratic in
    "n".
    
    Before we start allowing items to be removed, it would be
    nice to have a way to cover this case in linear time.
    
    The simplest solution is to make an assumption about the
    order in which tempfiles are added and removed from the
    list. If both operations iterate over the tempfiles in the
    same order, then by putting new items at the end of the list
    our removal search will always find its items at the
    beginning of the list. And indeed, that would work for the
    case of refs. But it creates a hidden dependency between
    unrelated parts of the code. If anybody changes the re...
    24d82185