diff options
author | Alberto Lerner <alerner@10gen.com> | 2013-05-06 10:46:42 -0400 |
---|---|---|
committer | Alberto Lerner <alerner@10gen.com> | 2013-05-06 10:48:15 -0400 |
commit | 10c5bd34f4973aae49e6f89fcb939f9b9e9318a7 (patch) | |
tree | 0c7abfa6776e855638b01536338e4ac36c5096d5 | |
parent | c18c7b22d8709dc63498eb38af0d6eda2d337de6 (diff) | |
download | mongo-10c5bd34f4973aae49e6f89fcb939f9b9e9318a7.tar.gz |
SERVER-7172 Allow init() to be called more than once in field parsing (for reuse).
-rw-r--r-- | src/mongo/db/field_ref.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/field_ref_test.cpp | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref.cpp b/src/mongo/db/field_ref.cpp index 8c74b478312..c3dbc47ed5d 100644 --- a/src/mongo/db/field_ref.cpp +++ b/src/mongo/db/field_ref.cpp @@ -25,6 +25,10 @@ namespace mongo { return; } + if (_size != 0) { + clear(); + } + // We guarantee that accesses through getPart() will be valid while 'this' is. So we // take a copy. We're going to be "chopping" up the copy into c-strings. _fieldBase.reset(new char[dottedField.size()+1]); diff --git a/src/mongo/db/field_ref_test.cpp b/src/mongo/db/field_ref_test.cpp index e84a9d1158a..cdf4aa7ad92 100644 --- a/src/mongo/db/field_ref_test.cpp +++ b/src/mongo/db/field_ref_test.cpp @@ -66,6 +66,17 @@ namespace { ASSERT_EQUALS(fieldRef.dottedField(), field); } + TEST(Normal, ParseTwice) { + string field = "a"; + FieldRef fieldRef; + for (int i = 0; i < 2; i++) { + fieldRef.parse(field); + ASSERT_EQUALS(fieldRef.numParts(), 1U); + ASSERT_EQUALS(fieldRef.getPart(0), field); + ASSERT_EQUALS(fieldRef.dottedField(), field); + } + } + TEST(Normal, MulitplePartsVariable) { const char* parts[] = {"a", "b", "c", "d", "e"}; size_t size = sizeof(parts)/sizeof(char*); |