From 4a148905f94ed24c11a1e15b032b43248a01413b Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Thu, 20 Dec 2012 16:47:35 -0500 Subject: Use StringData rather than c-strings internally in Document --- src/mongo/db/pipeline/document.cpp | 6 +++--- src/mongo/db/pipeline/document_internal.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/mongo/db') diff --git a/src/mongo/db/pipeline/document.cpp b/src/mongo/db/pipeline/document.cpp index 43fdbf3b75d..725507ba432 100644 --- a/src/mongo/db/pipeline/document.cpp +++ b/src/mongo/db/pipeline/document.cpp @@ -217,7 +217,7 @@ namespace mongo { void Document::toBson(BSONObjBuilder* pBuilder) const { for (DocumentStorageIterator it = storage().iterator(); !it.atEnd(); it.advance()) { - *pBuilder << it->name << it->val; + *pBuilder << it->nameSD() << it->val; } } @@ -333,7 +333,7 @@ namespace mongo { const ValueElement& rField = rIt.get(); const ValueElement& lField = lIt.get(); - const int nameCmp = strcmp(lField.name, rField.name); + const int nameCmp = lField.nameSD().compare(rField.nameSD()); if (nameCmp) return nameCmp; // field names are unequal @@ -354,7 +354,7 @@ namespace mongo { const char* prefix = "{"; for (DocumentStorageIterator it = storage().iterator(); !it.atEnd(); it.advance()) { - out << prefix << it->name << ": " << it->val.toString(); + out << prefix << it->nameSD() << ": " << it->val.toString(); prefix = ", "; } out << '}'; diff --git a/src/mongo/db/pipeline/document_internal.h b/src/mongo/db/pipeline/document_internal.h index eab7778e6b6..d639a5f262b 100644 --- a/src/mongo/db/pipeline/document_internal.h +++ b/src/mongo/db/pipeline/document_internal.h @@ -55,7 +55,7 @@ namespace mongo { Value val; Position nextCollision; // Position of next field with same hashBucket const int nameLen; // doesn't include '\0' - const char name[1]; // pointer to start of name + const char _name[1]; // pointer to start of name (use nameSD instead) ValueElement* next() { return align(plusBytes(sizeof(ValueElement) + nameLen)); @@ -65,7 +65,7 @@ namespace mongo { return align(plusBytes(sizeof(ValueElement) + nameLen)); } - StringData nameSD() const { return StringData(name, nameLen); } + StringData nameSD() const { return StringData(_name, nameLen); } // helpers for doing pointer arithmetic with this class -- cgit v1.2.1