void PeerTable::add(const Peer& peer) { if (containsName(peer.getName())) throw ModelError("A peer with the same name already exists"); if (containsId(peer.getId())) throw ModelError("A peer with the same id already exists"); _peers.push_back(peer); }
ExpiryTimerImpl::Id ExpiryTimerImpl::generateId() { Id newId = m_dist(m_mt); std::lock_guard< std::mutex > lock{ m_mutex }; while (newId == INVALID_ID || containsId(newId)) { newId = m_dist(m_mt); } return newId; }
bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, unsigned length) { if (m_propertyVector.isEmpty()) return false; CSSProperty* properties = m_propertyVector.data(); unsigned oldSize = m_propertyVector.size(); unsigned newIndex = 0; for (unsigned oldIndex = 0; oldIndex < oldSize; ++oldIndex) { const CSSProperty& property = properties[oldIndex]; if (containsId(set, length, property.id())) continue; // Modify m_propertyVector in-place since this method is performance-sensitive. properties[newIndex++] = properties[oldIndex]; } if (newIndex != oldSize) { m_propertyVector.shrink(newIndex); return true; } return false; }