Replace sequences of v.push_back(v[i]); v.erase(&v[i]); with std::rotate (NFC)
authorMehdi Amini <joker.eph@gmail.com>
Sat, 14 Nov 2020 00:46:30 +0000 (00:46 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Sat, 14 Nov 2020 00:55:33 +0000 (00:55 +0000)
commit42e88bd6b18597fe0a46ee9663d4e2cf2f7a4e57
tree97cbeee72b45208ad5318a0c9a72bd71fd34c09f
parent703ef17e7a0a0f51e1d000bb1f71ad437a9933e4
Replace sequences of v.push_back(v[i]); v.erase(&v[i]); with std::rotate (NFC)

The code has a few sequence that looked like:

    Ops.push_back(Ops[0]);
    Ops.erase(Ops.begin());

And are equivalent to:

    std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());

The latter has the advantage of never reallocating the vector, which
would be a bug in the original code as push_back would read from the
memory it deallocated.
clang/lib/CodeGen/CGBuiltin.cpp