summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-05-15 14:22:46 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-21 14:06:46 +0000
commit00b54ad9218464d78451c396ac1a958ca63ce3c7 (patch)
treed70ff3cfc270253143b002a8d7df490a119988f3 /src/mongo/db/geo
parent8cb02c375ad128bca9bad7edcc29a8c55fbd9269 (diff)
downloadmongo-00b54ad9218464d78451c396ac1a958ca63ce3c7.tar.gz
SERVER-47969 Use Pooled KeyString builder in all index key generators where possible
Also ensure no quadratic insert behavior into the KeyStringSet
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r--src/mongo/db/geo/hash.cpp12
-rw-r--r--src/mongo/db/geo/hash.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/db/geo/hash.cpp b/src/mongo/db/geo/hash.cpp
index 25437d51769..c2b7009a86d 100644
--- a/src/mongo/db/geo/hash.cpp
+++ b/src/mongo/db/geo/hash.cpp
@@ -480,7 +480,8 @@ void GeoHash::clearUnusedBits() {
_hash &= ~mask;
}
-static void appendHashToBuilder(long long hash, BSONObjBuilder* builder, const char* fieldName) {
+namespace {
+void appendHashToBuilder(long long hash, BSONObjBuilder* builder, const char* fieldName) {
char buf[8];
if constexpr (kNativeLittle) {
// Reverse the order of bytes when copying between BinData and GeoHash.
@@ -495,7 +496,8 @@ static void appendHashToBuilder(long long hash, BSONObjBuilder* builder, const c
builder->appendBinData(fieldName, 8, bdtCustom, buf);
}
-static void appendHashToKeyString(long long hash, KeyString::Builder* ks) {
+template <typename KeyStringBuilder>
+void appendHashToKeyString(long long hash, KeyStringBuilder* ks) {
char buf[8];
if constexpr (kNativeLittle) {
// Reverse the order of bytes when copying between BinData and GeoHash.
@@ -509,6 +511,7 @@ static void appendHashToKeyString(long long hash, KeyString::Builder* ks) {
}
ks->appendBinData(BSONBinData(buf, 8, bdtCustom));
}
+} // namespace
void GeoHash::appendHashMin(BSONObjBuilder* builder, const char* fieldName) const {
// The min bound of a GeoHash region has all the unused suffix bits set to 0
@@ -520,6 +523,11 @@ void GeoHash::appendHashMin(KeyString::Builder* ks) const {
appendHashToKeyString(_hash, ks);
}
+void GeoHash::appendHashMin(KeyString::PooledBuilder* ks) const {
+ // The min bound of a GeoHash region has all the unused suffix bits set to 0
+ appendHashToKeyString(_hash, ks);
+}
+
void GeoHash::appendHashMax(BSONObjBuilder* builder, const char* fieldName) const {
// The max bound of a GeoHash region has all the unused suffix bits set to 1
long long suffixMax = ~(geoBitSets.allX[_bits] | geoBitSets.allY[_bits]);
diff --git a/src/mongo/db/geo/hash.h b/src/mongo/db/geo/hash.h
index 6b59034accc..6342c384a85 100644
--- a/src/mongo/db/geo/hash.h
+++ b/src/mongo/db/geo/hash.h
@@ -114,6 +114,7 @@ public:
void appendHashMin(BSONObjBuilder* builder, const char* fieldName) const;
// Append the minimum range of the hash to the KeyString provided (inclusive)
void appendHashMin(KeyString::Builder* ks) const;
+ void appendHashMin(KeyString::PooledBuilder* ks) const;
// Append the maximum range of the hash to the builder provided (inclusive)
void appendHashMax(BSONObjBuilder* builder, const char* fieldName) const;