mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
remove nkeys from Ordering slightly faster
This commit is contained in:
parent
73b97fda11
commit
ac1232db80
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user