From d134ba27aa7f2c4eb8fc4b1331c8331f5914bfc6 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Mon, 14 Jul 2014 11:57:29 -0400 Subject: SERVER-14482 Add add missing appendX methods to BSONArrayBuilder --- src/mongo/bson/mutable/document.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/mongo/bson/mutable/document.cpp') diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp index 5057ab2d69a..e3eccfb18c7 100644 --- a/src/mongo/bson/mutable/document.cpp +++ b/src/mongo/bson/mutable/document.cpp @@ -2102,6 +2102,23 @@ namespace mutablebson { BufBuilder& buffer; }; + static void appendElement(BSONObjBuilder* builder, + const BSONElement& element, + const StringData* fieldName) { + if (fieldName) + builder->appendAs(element, *fieldName); + else + builder->append(element); + } + + // BSONArrayBuilder should not be appending elements with a fieldName + static void appendElement(BSONArrayBuilder* builder, + const BSONElement& element, + const StringData* fieldName) { + invariant(!fieldName); + builder->append(element); + } + } // namespace template @@ -2111,11 +2128,7 @@ namespace mutablebson { const ElementRep& rep = getElementRep(repIdx); if (hasValue(rep)) { - const BSONElement element = getSerializedElement(rep); - if (fieldName) - builder->appendAs(element, *fieldName); - else - builder->append(element); + appendElement(builder, getSerializedElement(rep), fieldName); } else { const BSONType type = getType(rep); const StringData subName = fieldName ? *fieldName : getFieldName(rep); -- cgit v1.2.1