diff options
author | Mathias Stearn <mathias@10gen.com> | 2011-08-08 17:04:23 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2011-08-08 19:52:56 -0400 |
commit | c69a6247ed2b849503d1964674efd71cd3c65ffa (patch) | |
tree | 92ee33da7b2a9281a702e35f2e7bfbb7f8facf59 | |
parent | 2749b350f11be618fcd0cbf3b550c2142c231801 (diff) | |
download | mongo-c69a6247ed2b849503d1964674efd71cd3c65ffa.tar.gz |
fast-path for ShardKey::extractFields to create less garbage if already in key form
-rw-r--r-- | s/chunk.cpp | 4 | ||||
-rw-r--r-- | s/shardkey.h | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp index b1984179864..6a195d8d25d 100644 --- a/s/chunk.cpp +++ b/s/chunk.cpp @@ -666,8 +666,10 @@ namespace mongo { } if ( c ) { - if ( c->contains( obj ) ) + if ( c->contains( key ) ){ + dassert(c->contains(key)); // doesn't use fast-path in extractKey return c; + } PRINT(foo); PRINT(*c); diff --git a/s/shardkey.h b/s/shardkey.h index 96301ffe093..976cff09591 100644 --- a/s/shardkey.h +++ b/s/shardkey.h @@ -102,7 +102,21 @@ namespace mongo { }; inline BSONObj ShardKeyPattern::extractKey(const BSONObj& from) const { - BSONObj k = from.extractFields(pattern); + BSONObj k = from; + bool needExtraction = false; + + BSONObjIterator a(from); + BSONObjIterator b(pattern); + while (a.more() && b.more()){ + if (strcmp(a.next().fieldName(), b.next().fieldName()) != 0){ + needExtraction = true; + break; + } + } + + if (needExtraction || a.more() != b.more()) + k = from.extractFields(pattern); + uassert(13334, "Shard Key must be less than 512 bytes", k.objsize() < 512); return k; } |