diff options
author | Mathias Stearn <mathias@10gen.com> | 2011-08-08 18:12:15 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2011-08-08 19:52:56 -0400 |
commit | e0391514a811bbb404397a74e7ce631d80581d6e (patch) | |
tree | b4af3026b9b605befd3bb109037d27014ebf9dc9 /client | |
parent | 0e20be567e38e835d8a2df17ba030391bbbb00ee (diff) | |
download | mongo-e0391514a811bbb404397a74e7ce631d80581d6e.tar.gz |
in-place serverNameCompare
Diffstat (limited to 'client')
-rw-r--r-- | client/connpool.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp index 0548006d241..2d7c37bfbda 100644 --- a/client/connpool.cpp +++ b/client/connpool.cpp @@ -307,20 +307,36 @@ namespace mongo { } bool DBConnectionPool::serverNameCompare::operator()( const string& a , const string& b ) const{ - string ap = str::before( a , "/" ); - string bp = str::before( b , "/" ); - - return ap < bp; + const char* ap = a.c_str(); + const char* bp = b.c_str(); + + while (true){ + if (*ap == '\0' || *ap == '/'){ + if (*bp == '\0' || *bp == '/') + return false; // equal strings + else + return true; // a is shorter + } + + if (*bp == '\0' || *bp == '/') + return false; // b is shorter + + if ( *ap < *bp) + return true; + else if (*ap > *bp) + return false; + + ++ap; + ++bp; + } + assert(false); } bool DBConnectionPool::poolKeyCompare::operator()( const PoolKey& a , const PoolKey& b ) const { - string ap = str::before( a.ident , "/" ); - string bp = str::before( b.ident , "/" ); - - if ( ap < bp ) + if (DBConnectionPool::serverNameCompare()( a.ident , b.ident )) return true; - if ( ap > bp ) + if (DBConnectionPool::serverNameCompare()( b.ident , a.ident )) return false; return a.timeout < b.timeout; |