summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2019-03-29 10:53:49 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2019-04-10 13:46:10 -0400
commit5f60f56987ac81e1190c16ba574200303fffc256 (patch)
treeccb3f51c17403476bc03970c4ebef522df3a5362 /src/mongo/db/query
parent26b0675fb073f0185728d98ad81950ca9744c5b8 (diff)
downloadmongo-5f60f56987ac81e1190c16ba574200303fffc256.tar.gz
SERVER-40463 String utils output StringData instead of std::string
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/parsed_projection.cpp13
-rw-r--r--src/mongo/db/query/parsed_projection.h2
-rw-r--r--src/mongo/db/query/plan_enumerator.cpp8
3 files changed, 10 insertions, 13 deletions
diff --git a/src/mongo/db/query/parsed_projection.cpp b/src/mongo/db/query/parsed_projection.cpp
index 415087e7fb1..aaa3bd36f3d 100644
--- a/src/mongo/db/query/parsed_projection.cpp
+++ b/src/mongo/db/query/parsed_projection.cpp
@@ -231,15 +231,15 @@ Status ParsedProjection::make(OperationContext* opCtx,
"Cannot specify positional operator and $elemMatch.");
}
- std::string after = str::after(elem.fieldName(), ".$");
- if (str::contains(after, ".$")) {
+ StringData after = str::after(elem.fieldNameStringData(), ".$");
+ if (after.find(".$"_sd) != std::string::npos) {
str::stream ss;
ss << "Positional projection '" << elem.fieldName() << "' contains "
<< "the positional operator more than once.";
return Status(ErrorCodes::BadValue, ss);
}
- std::string matchfield = str::before(elem.fieldName(), '.');
+ StringData matchfield = str::before(elem.fieldNameStringData(), '.');
if (query && !_hasPositionalOperatorMatch(query, matchfield)) {
str::stream ss;
ss << "Positional projection '" << elem.fieldName() << "' does not "
@@ -388,7 +388,7 @@ bool ParsedProjection::_isPositionalOperator(const char* fieldName) {
// static
bool ParsedProjection::_hasPositionalOperatorMatch(const MatchExpression* const query,
- const std::string& matchfield) {
+ StringData matchfield) {
if (query->getCategory() == MatchExpression::MatchCategory::kLogical) {
for (unsigned int i = 0; i < query->numChildren(); ++i) {
if (_hasPositionalOperatorMatch(query->getChild(i), matchfield)) {
@@ -397,14 +397,13 @@ bool ParsedProjection::_hasPositionalOperatorMatch(const MatchExpression* const
}
} else {
StringData queryPath = query->path();
- const char* pathRawData = queryPath.rawData();
// We have to make a distinction between match expressions that are
// initialized with an empty field/path name "" and match expressions
// for which the path is not meaningful (eg. $where).
- if (!pathRawData) {
+ if (!queryPath.rawData()) {
return false;
}
- std::string pathPrefix = str::before(pathRawData, '.');
+ StringData pathPrefix = str::before(queryPath, '.');
return pathPrefix == matchfield;
}
return false;
diff --git a/src/mongo/db/query/parsed_projection.h b/src/mongo/db/query/parsed_projection.h
index e22a594a528..0a5ee6de3c2 100644
--- a/src/mongo/db/query/parsed_projection.h
+++ b/src/mongo/db/query/parsed_projection.h
@@ -144,7 +144,7 @@ private:
* Does not take ownership of 'query'.
*/
static bool _hasPositionalOperatorMatch(const MatchExpression* const query,
- const std::string& matchfield);
+ StringData matchfield);
// Track fields needed by the projection so that the query planner can perform projection
// analysis and possibly give us a covered projection.
diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp
index 8bc87ce75cb..7c6d498007c 100644
--- a/src/mongo/db/query/plan_enumerator.cpp
+++ b/src/mongo/db/query/plan_enumerator.cpp
@@ -48,11 +48,9 @@ using std::string;
using std::vector;
std::string getPathPrefix(std::string path) {
- if (str::contains(path, '.')) {
- return str::before(path, '.');
- } else {
- return path;
- }
+ if (auto dot = path.find('.'); dot != path.npos)
+ path.resize(dot);
+ return path;
}
/**