50int RemoveAt(RepeatedType* array,
const IndexContainer& indices) {
51 if (indices.size() == 0) {
54 const int num_indices = indices.size();
55 const int num_elements = array->size();
56 DCHECK_LE(num_indices, num_elements);
57 if (num_indices == num_elements) {
62 typename IndexContainer::const_iterator remove_iter = indices.begin();
63 int write_index = *(remove_iter++);
64 for (
int scan = write_index + 1; scan < num_elements; ++scan) {
65 if (remove_iter != indices.end() && *remove_iter == scan) {
68 array->SwapElements(scan, write_index++);
71 DCHECK_EQ(write_index, num_elements - num_indices);
89int RemoveIf(RepeatedPtrField<T>* array,
const Pred& pr) {
90 T**
const begin = array->mutable_data();
91 T**
const end = begin + array->size();
93 while (write < end && !pr(*write)) ++write;
94 if (write == end)
return 0;
96 for (T** scan = write + 1; scan < end; ++scan) {
97 if (!pr(*scan)) std::swap(*scan, *write++);