Skip to content
  • Mark OLESEN's avatar
    ENH: improve UPtrList sorting · 521bdf0f
    Mark OLESEN authored
    - adjust nullptr checks to discourage flip-flop when confronted with
      multiple null values.
    
         Old:   (a && b) ? (*a < *b) : bool(a);
         New:   (a && b) ? (*a < *b) : !b;
    
      comparing (non-null < null) and (null < non-null) behaves
      identically, but comparing (null < null) now tests as true
      (ie, already sorted) whereas before it would have been false
      (ie, needs a swap)
    
    - add UPtrList trimTrailingNull(), which reduces the effective
      (addressable) list size to ignore any trailing null pointers, but
      without reallocation. This is particularly useful when creating a
      UPtrList list view. For example,
    
         UPtrList<some_iterator> validValues(container.size());
    
         ...Loop to add valid entries, by some criteria...
    
         // Shorten list to hide null entries
         validValues.trimTrailingNull();
    
       This list view now only needs a single allocation, whereas using
       a resize (as was previously necessary) could invoke a second
       allocation, as well as recopying.
    521bdf0f