Abdelrazak Younes <[EMAIL PROTECTED]> writes:
Just some little observations.
Angus
/// Copy constructor.
RandomAccessList(RandomAccessList const & ext_list) {
- for (const_iterator it = ext_list.begin();
- it != ext_list.end(); ++it)
+ // Don't recompute end on each iteration of the loop.
+ const_iterator const end = ext_list.end();
+ for (const_iterator it = ext_list.begin(); it != end; ++it)
push_back(*it);
}
/// Partial copy constructor.
/**
Copy "length" elements from ext_list beginning at pos.
*/
RandomAccessList(RandomAccessList const & ext_list,
size_t pos, size_t length) {
- for (size_t i = pos; i != pos+length; ++i)
+ size_t const end = pos + length;
+ for (size_t i = pos; i != end; ++i)
push_back(ext_list[i]);
}
/// Copy "length" elements from ext_list beginning at pos.
void assign(RandomAccessList const & ext_list,
size_t pos, size_t length) {
clear();
- for (size_t i = pos; i != pos+length; ++i)
+ size_t const end = pos + length;
+ for (size_t i = pos; i != end; ++i)
push_back(ext_list[i]);
}
/// Erases 'length' elements starting from pos.
/**
- \todo This could be optimized a bit by rebuilding ItVector
- instead of multiple deletion.
+ TODO: use std::remove_if and vector<>::erase, passing the
+ same predicate to remove_if as is used by erase(size_t);
+ Refactor the other erase() member funtions to use this predicate
+ also?
*/
bool erase(size_t pos, size_t length) {
bool result=true;
for (size_t i = pos; i != pos+length; ++i)
result = result && erase(i);
return result;
}