[PATCH] D55234: Do not use a hash table to uniquify mergeable strings.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 17:01:06 PST 2018


MaskRay added a comment.

The one-entry cache I mentioned is like the following (**I don't say I suggest doing that as it is so complicated with probably so little value**):

  size_t I;
  if (Offset < LastOffset) {
    I = std::upper_bound(Pieces.begin(), Pieces.begin() + LastIdx, Offset,
                         [](uint64_t Offset, SectionPiece P) {
                           return Offset < P.InputOff;
                         }) -
        Pieces.begin();
  } else {
    I = LastIdx;
    if (I < Pieces.size() && Pieces[I].InputOff <= Offset)
      ++I;
    if (I < Pieces.size() && Pieces[I].InputOff <= Offset)
      I = std::upper_bound(Pieces.begin() + I + 1, Pieces.end(), Offset,
                           [](uint64_t Offset, SectionPiece P) {
                             return Offset < P.InputOff;
                           }) -
          Pieces.begin();
  }
  
  LastOffset = Offset;
  LastIdx = I;
  return &Pieces[I - 1];

Actually `upper_bound` is not the best choice here, a slow starting step sizes are better: 1,2,4,8,16,(slow start process)   8,4,2,1 (regular binary search steps)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55234/new/

https://reviews.llvm.org/D55234





More information about the llvm-commits mailing list