diff options
author | Dwight <dwight@10gen.com> | 2011-06-16 14:46:27 -0400 |
---|---|---|
committer | Dwight <dwight@10gen.com> | 2011-06-16 14:46:27 -0400 |
commit | ac1232db80be19e662d3bdd14985036d19467e22 (patch) | |
tree | cb47445a2a3255e1c4c8ddb472a6657aa7346833 /bson | |
parent | 73b97fda112e0ade208f1120b7c34a0eb6829a3c (diff) | |
download | mongo-ac1232db80be19e662d3bdd14985036d19467e22.tar.gz |
remove nkeys from Ordering slightly faster
Diffstat (limited to 'bson')
-rw-r--r-- | bson/ordering.h | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/bson/ordering.h b/bson/ordering.h index 749e20dd4ea..bca3296f340 100644 --- a/bson/ordering.h +++ b/bson/ordering.h @@ -19,15 +19,22 @@ namespace mongo { - /** A precomputation of a BSON key pattern. + // todo: ideally move to db/ instead of bson/, but elim any dependencies first + + /** A precomputation of a BSON index or sort key pattern. That is something like: + { a : 1, b : -1 } The constructor is private to make conversion more explicit so we notice where we call make(). Over time we should push this up higher and higher. - */ + */ class Ordering { - const unsigned bits; - const unsigned nkeys; - Ordering(unsigned b,unsigned n) : bits(b),nkeys(n) { } + unsigned bits; + Ordering(unsigned b) : bits(b) { } public: + Ordering(const Ordering& r) : bits(r.bits) { } + void operator=(const Ordering& r) { + bits = r.bits; + } + /** so, for key pattern { a : 1, b : -1 } get(0) == 1 get(1) == -1 @@ -39,12 +46,12 @@ namespace mongo { // for woCompare... unsigned descending(unsigned mask) const { return bits & mask; } - operator string() const { + /*operator string() const { StringBuilder buf(32); for ( unsigned i=0; i<nkeys; i++) buf.append( get(i) > 0 ? "+" : "-" ); return buf.str(); - } + }*/ static Ordering make(const BSONObj& obj) { unsigned b = 0; @@ -59,7 +66,7 @@ namespace mongo { b |= (1 << n); n++; } - return Ordering(b,n); + return Ordering(b); } }; |