summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-04-26 19:19:01 -0400
committerMathias Stearn <mathias@10gen.com>2016-04-29 19:11:15 -0400
commit30e24df25429b25eee51da18ad1efa8505b1c140 (patch)
treee5e717f0ea7a9b41d77b762889b8caa9c913c640 /src/mongo/db/ops
parent8438c5c04a65dc2b7b13106934baf3ae2c21de99 (diff)
downloadmongo-30e24df25429b25eee51da18ad1efa8505b1c140.tar.gz
SERVER-23873 Optimize fixDocumentForInsert
Diffstat (limited to 'src/mongo/db/ops')
-rw-r--r--src/mongo/db/ops/insert.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index 7086d79707d..de198beac53 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -45,12 +45,12 @@ StatusWith<BSONObj> fixDocumentForInsert(const BSONObj& doc) {
<< ". size in bytes: " << doc.objsize()
<< ", max size: " << BSONObjMaxUserSize);
- bool firstElementIsId = doc.firstElement().fieldNameStringData() == "_id";
+ bool firstElementIsId = false;
bool hasTimestampToFix = false;
bool hadId = false;
{
BSONObjIterator i(doc);
- while (i.more()) {
+ for (bool isFirstElement = true; i.more(); isFirstElement = false) {
BSONElement e = i.next();
if (e.type() == bsonTimestamp && e.timestampValue() == 0) {
@@ -59,19 +59,18 @@ StatusWith<BSONObj> fixDocumentForInsert(const BSONObj& doc) {
hasTimestampToFix = true;
}
- const char* fieldName = e.fieldName();
+ auto fieldName = e.fieldNameStringData();
if (fieldName[0] == '$') {
- return StatusWith<BSONObj>(ErrorCodes::BadValue,
- str::stream()
- << "Document can't have $ prefixed field names: "
- << e.fieldName());
+ return StatusWith<BSONObj>(
+ ErrorCodes::BadValue,
+ str::stream() << "Document can't have $ prefixed field names: " << fieldName);
}
// check no regexp for _id (SERVER-9502)
// also, disallow undefined and arrays
// Make sure _id isn't duplicated (SERVER-19361).
- if (str::equals(fieldName, "_id")) {
+ if (fieldName == "_id") {
if (e.type() == RegEx) {
return StatusWith<BSONObj>(ErrorCodes::BadValue, "can't use a regex for _id");
}
@@ -93,6 +92,7 @@ StatusWith<BSONObj> fixDocumentForInsert(const BSONObj& doc) {
"can't have multiple _id fields in one document");
} else {
hadId = true;
+ firstElementIsId = isFirstElement;
}
}
}