diff options
author | Andrew Morrow <acm@mongodb.com> | 2016-06-12 09:33:35 -0400 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2016-06-13 15:29:10 -0400 |
commit | 642dda763795d7c62753e6e6391b30b1670612b4 (patch) | |
tree | 8e40cdd257d56f7495b2d60bc7da91289a7d7834 /src/mongo/bson/mutable | |
parent | 9fd6bc9fb1a9321447efa964b7568da740b23bcf (diff) | |
download | mongo-642dda763795d7c62753e6e6391b30b1670612b4.tar.gz |
SERVER-24530 Use invariant instead of verify in mutable bson
Also, mark the non-throwing termination points in assert_util noexcept
Diffstat (limited to 'src/mongo/bson/mutable')
-rw-r--r-- | src/mongo/bson/mutable/document.cpp | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp index 5ae92341217..da1486dcb24 100644 --- a/src/mongo/bson/mutable/document.cpp +++ b/src/mongo/bson/mutable/document.cpp @@ -497,8 +497,8 @@ uint32_t getElementOffset(const BSONObj& object, const BSONElement& elt) { const ptrdiff_t offset = eltRaw - objRaw; // BSON documents express their size as an int32_t so we should always be able to // express the offset as a uint32_t. - verify(offset > 0); - verify(offset <= std::numeric_limits<int32_t>::max()); + invariant(offset > 0); + invariant(offset <= std::numeric_limits<int32_t>::max()); return offset; } @@ -634,7 +634,7 @@ public: if (id < kFastReps) { return _fastElements[id] = defaultRep; } else { - verify(id <= Element::kMaxRepIdx); + invariant(id <= Element::kMaxRepIdx); if (kDebugBuild && paranoid) { // Force all reps to new addresses to help catch invalid rep usage. @@ -683,7 +683,7 @@ public: // Insert the given BSONObj and return an ID for it. ElementRep::ObjIdx insertObject(const BSONObj& newObj) { const size_t objIdx = _objects.size(); - verify(objIdx <= kMaxObjIdx); + invariant(objIdx <= kMaxObjIdx); _objects.push_back(newObj); if (kDebugBuild && paranoid) { // Force reallocation to catch use after invalidation. @@ -1088,9 +1088,9 @@ private: }; Status Element::addSiblingLeft(Element e) { - verify(ok()); - verify(e.ok()); - verify(_doc == e._doc); + invariant(ok()); + invariant(e.ok()); + invariant(_doc == e._doc); Document::Impl& impl = getDocument().getImpl(); ElementRep& newRep = impl.getElementRep(e._repIdx); @@ -1139,9 +1139,9 @@ Status Element::addSiblingLeft(Element e) { } Status Element::addSiblingRight(Element e) { - verify(ok()); - verify(e.ok()); - verify(_doc == e._doc); + invariant(ok()); + invariant(e.ok()); + invariant(_doc == e._doc); Document::Impl& impl = getDocument().getImpl(); ElementRep* newRep = &impl.getElementRep(e._repIdx); @@ -1201,7 +1201,7 @@ Status Element::addSiblingRight(Element e) { } Status Element::remove() { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); // We need to realize any opaque right sibling, because we are going to need to set its @@ -1249,7 +1249,7 @@ Status Element::remove() { } Status Element::rename(StringData newName) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); if (_repIdx == kRootRepIdx) @@ -1302,7 +1302,7 @@ Status Element::rename(StringData newName) { } Element Element::leftChild() const { - verify(ok()); + invariant(ok()); // Capturing Document::Impl by non-const ref exploits the constness loophole // created by our Impl so that we can let leftChild be lazily evaluated, even for a @@ -1314,7 +1314,7 @@ Element Element::leftChild() const { } Element Element::rightChild() const { - verify(ok()); + invariant(ok()); // Capturing Document::Impl by non-const ref exploits the constness loophole // created by our Impl so that we can let leftChild be lazily evaluated, even for a @@ -1326,7 +1326,7 @@ Element Element::rightChild() const { } bool Element::hasChildren() const { - verify(ok()); + invariant(ok()); // Capturing Document::Impl by non-const ref exploits the constness loophole // created by our Impl so that we can let leftChild be lazily evaluated, even for a // const Element. @@ -1335,7 +1335,7 @@ bool Element::hasChildren() const { } Element Element::leftSibling(size_t distance) const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); Element::RepIdx current = _repIdx; while ((current != kInvalidRepIdx) && (distance-- != 0)) { @@ -1346,7 +1346,7 @@ Element Element::leftSibling(size_t distance) const { } Element Element::rightSibling(size_t distance) const { - verify(ok()); + invariant(ok()); // Capturing Document::Impl by non-const ref exploits the constness loophole // created by our Impl so that we can let rightSibling be lazily evaluated, even for a @@ -1359,7 +1359,7 @@ Element Element::rightSibling(size_t distance) const { } Element Element::parent() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const Element::RepIdx parentIdx = impl.getElementRep(_repIdx).parent; dassert(parentIdx != kOpaqueRepIdx); @@ -1367,7 +1367,7 @@ Element Element::parent() const { } Element Element::findNthChild(size_t n) const { - verify(ok()); + invariant(ok()); Document::Impl& impl = _doc->getImpl(); Element::RepIdx current = _repIdx; current = impl.resolveLeftChild(current); @@ -1377,7 +1377,7 @@ Element Element::findNthChild(size_t n) const { } Element Element::findFirstChildNamed(StringData name) const { - verify(ok()); + invariant(ok()); Document::Impl& impl = _doc->getImpl(); Element::RepIdx current = _repIdx; current = impl.resolveLeftChild(current); @@ -1388,7 +1388,7 @@ Element Element::findFirstChildNamed(StringData name) const { } Element Element::findElementNamed(StringData name) const { - verify(ok()); + invariant(ok()); Document::Impl& impl = _doc->getImpl(); Element::RepIdx current = _repIdx; while ((current != kInvalidRepIdx) && (impl.getFieldName(impl.getElementRep(current)) != name)) @@ -1397,7 +1397,7 @@ Element Element::findElementNamed(StringData name) const { } size_t Element::countSiblingsLeft() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); Element::RepIdx current = _repIdx; size_t result = 0; @@ -1412,7 +1412,7 @@ size_t Element::countSiblingsLeft() const { } size_t Element::countSiblingsRight() const { - verify(ok()); + invariant(ok()); Document::Impl& impl = _doc->getImpl(); Element::RepIdx current = _repIdx; size_t result = 0; @@ -1426,7 +1426,7 @@ size_t Element::countSiblingsRight() const { } size_t Element::countChildren() const { - verify(ok()); + invariant(ok()); Document::Impl& impl = _doc->getImpl(); Element::RepIdx current = _repIdx; current = impl.resolveLeftChild(current); @@ -1439,14 +1439,14 @@ size_t Element::countChildren() const { } bool Element::hasValue() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); return impl.hasValue(thisRep); } bool Element::isNumeric() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const BSONType type = impl.getType(thisRep); @@ -1455,7 +1455,7 @@ bool Element::isNumeric() const { } bool Element::isIntegral() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const BSONType type = impl.getType(thisRep); @@ -1463,7 +1463,7 @@ bool Element::isIntegral() const { } const BSONElement Element::getValue() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); if (impl.hasValue(thisRep)) @@ -1489,8 +1489,8 @@ SafeNum Element::getValueSafeNum() const { int Element::compareWithElement(const ConstElement& other, bool considerFieldName, const StringData::ComparatorInterface* comparator) const { - verify(ok()); - verify(other.ok()); + invariant(ok()); + invariant(other.ok()); // Short circuit a tautological compare. if ((_repIdx == other.getIdx()) && (_doc == &other.getDocument())) @@ -1572,7 +1572,7 @@ int Element::compareWithElement(const ConstElement& other, int Element::compareWithBSONElement(const BSONElement& other, bool considerFieldName, const StringData::ComparatorInterface* comparator) const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); @@ -1613,11 +1613,11 @@ int Element::compareWithBSONElement(const BSONElement& other, int Element::compareWithBSONObj(const BSONObj& other, bool considerFieldName, const StringData::ComparatorInterface* comparator) const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); - verify(!impl.isLeaf(thisRep)); + invariant(!impl.isLeaf(thisRep)); // We are dealing with either two objects, or two arrays. We need to consider the child // elements individually. We walk two iterators forward over the children and compare @@ -1643,10 +1643,10 @@ int Element::compareWithBSONObj(const BSONObj& other, } void Element::writeTo(BSONObjBuilder* const builder) const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); - verify(impl.getType(thisRep) == mongo::Object); + invariant(impl.getType(thisRep) == mongo::Object); if (thisRep.parent == kInvalidRepIdx && _repIdx == kRootRepIdx) { // If this is the root element, then we need to handle it differently, since it // doesn't have a field name and should embed directly, rather than as an object. @@ -1657,15 +1657,15 @@ void Element::writeTo(BSONObjBuilder* const builder) const { } void Element::writeArrayTo(BSONArrayBuilder* const builder) const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); - verify(impl.getType(thisRep) == mongo::Array); + invariant(impl.getType(thisRep) == mongo::Array); return impl.writeChildren(_repIdx, builder); } Status Element::setValueDouble(const double value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); ElementRep thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1674,7 +1674,7 @@ Status Element::setValueDouble(const double value) { } Status Element::setValueString(StringData value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(value)); @@ -1686,7 +1686,7 @@ Status Element::setValueString(StringData value) { } Status Element::setValueObject(const BSONObj& value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(value)); @@ -1698,7 +1698,7 @@ Status Element::setValueObject(const BSONObj& value) { } Status Element::setValueArray(const BSONObj& value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(value)); @@ -1712,7 +1712,7 @@ Status Element::setValueArray(const BSONObj& value) { Status Element::setValueBinary(const uint32_t len, mongo::BinDataType binType, const void* const data) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); // TODO: Alias check for binary data? @@ -1724,7 +1724,7 @@ Status Element::setValueBinary(const uint32_t len, } Status Element::setValueUndefined() { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1733,7 +1733,7 @@ Status Element::setValueUndefined() { } Status Element::setValueOID(const OID value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1742,7 +1742,7 @@ Status Element::setValueOID(const OID value) { } Status Element::setValueBool(const bool value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); ElementRep thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1751,7 +1751,7 @@ Status Element::setValueBool(const bool value) { } Status Element::setValueDate(const Date_t value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1760,7 +1760,7 @@ Status Element::setValueDate(const Date_t value) { } Status Element::setValueNull() { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1769,7 +1769,7 @@ Status Element::setValueNull() { } Status Element::setValueRegex(StringData re, StringData flags) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(re)); @@ -1782,7 +1782,7 @@ Status Element::setValueRegex(StringData re, StringData flags) { } Status Element::setValueDBRef(StringData ns, const OID oid) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(ns)); @@ -1794,7 +1794,7 @@ Status Element::setValueDBRef(StringData ns, const OID oid) { } Status Element::setValueCode(StringData value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(value)); @@ -1806,7 +1806,7 @@ Status Element::setValueCode(StringData value) { } Status Element::setValueSymbol(StringData value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(value)); @@ -1818,7 +1818,7 @@ Status Element::setValueSymbol(StringData value) { } Status Element::setValueCodeWithScope(StringData code, const BSONObj& scope) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); dassert(impl.doesNotAlias(code)); @@ -1831,7 +1831,7 @@ Status Element::setValueCodeWithScope(StringData code, const BSONObj& scope) { } Status Element::setValueInt(const int32_t value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); ElementRep thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1840,7 +1840,7 @@ Status Element::setValueInt(const int32_t value) { } Status Element::setValueTimestamp(const Timestamp value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1849,7 +1849,7 @@ Status Element::setValueTimestamp(const Timestamp value) { } Status Element::setValueLong(const int64_t value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); ElementRep thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1858,7 +1858,7 @@ Status Element::setValueLong(const int64_t value) { } Status Element::setValueDecimal(const Decimal128 value) { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); ElementRep thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1867,7 +1867,7 @@ Status Element::setValueDecimal(const Decimal128 value) { } Status Element::setValueMinKey() { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1876,7 +1876,7 @@ Status Element::setValueMinKey() { } Status Element::setValueMaxKey() { - verify(ok()); + invariant(ok()); Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); const StringData fieldName = impl.getFieldNameForNewElement(thisRep); @@ -1885,7 +1885,7 @@ Status Element::setValueMaxKey() { } Status Element::setValueBSONElement(const BSONElement& value) { - verify(ok()); + invariant(ok()); if (value.type() == mongo::EOO) return Status(ErrorCodes::IllegalOperation, "Can't set Element value to EOO"); @@ -1901,7 +1901,7 @@ Status Element::setValueBSONElement(const BSONElement& value) { } Status Element::setValueSafeNum(const SafeNum value) { - verify(ok()); + invariant(ok()); switch (value.type()) { case mongo::NumberInt: return setValueInt(value._value.int32Val); @@ -1918,7 +1918,7 @@ Status Element::setValueSafeNum(const SafeNum value) { } Status Element::setValueElement(ConstElement setFrom) { - verify(ok()); + invariant(ok()); // Can't set to your own root element, since this would create a circular document. if (_doc->root() == setFrom) { @@ -1942,25 +1942,25 @@ Status Element::setValueElement(ConstElement setFrom) { } BSONType Element::getType() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); return impl.getType(thisRep); } StringData Element::getFieldName() const { - verify(ok()); + invariant(ok()); const Document::Impl& impl = getDocument().getImpl(); const ElementRep& thisRep = impl.getElementRep(_repIdx); return impl.getFieldName(thisRep); } Status Element::addChild(Element e, bool front) { - // No need to verify(ok()) since we are only called from methods that have done so. + // No need to invariant(ok()) since we are only called from methods that have done so. dassert(ok()); - verify(e.ok()); - verify(_doc == e._doc); + invariant(e.ok()); + invariant(_doc == e._doc); Document::Impl& impl = getDocument().getImpl(); ElementRep& newRep = impl.getElementRep(e._repIdx); @@ -2008,7 +2008,7 @@ Status Element::addChild(Element e, bool front) { } Status Element::setValue(const Element::RepIdx newValueIdx) { - // No need to verify(ok()) since we are only called from methods that have done so. + // No need to invariant(ok()) since we are only called from methods that have done so. dassert(ok()); if (_repIdx == kRootRepIdx) |