Codechange: Replaced SmallVector::Erase() with std::vector::erase()

This commit is contained in:
Henry Wilson
2018-09-25 22:01:05 +01:00
committed by PeterN
parent 097328c3d7
commit ca2f33c6d0
8 changed files with 22 additions and 35 deletions

View File

@@ -115,7 +115,8 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
inline void Erase(Pair *pair)
{
assert(pair >= this->Begin() && pair < this->End());
SmallVector<Pair, S>::Erase(pair);
auto distance = pair - std::vector<Pair>::data();
std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
}
/**
@@ -126,11 +127,10 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline bool Erase(const T &key)
{
Pair *pair = this->Find(key);
if (pair == this->End())
return false;
auto pair = std::find(this->begin(), this->end(), key);
if (pair == this->end()) return false;
SmallVector<Pair, S>::Erase(pair);
std::vector<Pair>::erase(pair);
return true;
}

View File

@@ -103,18 +103,6 @@ public:
return it == std::vector<T>::end() ? -1 : it - std::vector<T>::begin();
}
/**
* Removes given item from this vector
* @param item item to remove
* @note it has to be pointer to item in this map. It is overwritten by the last item.
*/
inline void Erase(T *item)
{
assert(item >= this->Begin() && item < this->End());
*item = std::vector<T>::back();
std::vector<T>::pop_back();
}
/**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.