Skip to content

Commit

Permalink
Make the condition for compact inlinable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpavlik committed Jun 23, 2015
1 parent a40d9b7 commit 74b2428
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vrpn_EndpointContainer.C
Expand Up @@ -77,16 +77,14 @@ namespace vrpn {
container_.clear();
}

void EndpointContainer::compact()
void EndpointContainer::compact_()
{
if (needsCompact_) {
size_type before = get_full_container_size();
raw_iterator it = std::remove(begin_(), end_(), getNullEndpoint());
container_.resize(it - begin_());
needsCompact_ = false;
VRPN_EC_TRACE("Compact complete: was "
<< before << ", now " << get_full_container_size());
}
size_type before = get_full_container_size();
raw_iterator it = std::remove(begin_(), end_(), getNullEndpoint());
container_.resize(it - begin_());
needsCompact_ = false;
VRPN_EC_TRACE("Compact complete: was " << before << ", now "
<< get_full_container_size());
}

bool EndpointContainer::full() const
Expand Down
12 changes: 12 additions & 0 deletions vrpn_EndpointContainer.h
Expand Up @@ -131,6 +131,8 @@ namespace vrpn {
/// @{
/// @brief Implementation of acquire for the stored pointer type.
void acquire_(pointer endpoint);
/// @brief Do actual compact once we've determined it's necessary.
void compact_();

/// @}
container_type container_;
Expand Down Expand Up @@ -331,12 +333,22 @@ namespace vrpn {
}
return container_[i];
}

inline EndpointContainer::size_type
EndpointContainer::get_full_container_size() const
{
return container_.size();
}

// making this condition inline so that it has minimal overhead if
// we don't actually need to perform a compaction.
inline void EndpointContainer::compact()
{
if (needsCompact_) {
compact_();
}
}

inline EndpointIterator EndpointContainer::begin() const
{
return EndpointIterator(*this);
Expand Down

0 comments on commit 74b2428

Please sign in to comment.