0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

fix lexNumCmp with magic end of marker

This commit is contained in:
Eliot Horowitz 2010-08-25 18:30:51 -04:00
parent 666af2a1b9
commit c78415729e
3 changed files with 18 additions and 7 deletions

View File

@ -517,10 +517,12 @@ namespace mongo {
DEBUGUPDATE( "\t\t createNewFromMods root: " << root );
BSONObjIteratorSorted es( obj );
BSONElement e = es.next();
ModStateHolder::iterator m = _mods.lower_bound( root );
ModStateHolder::iterator mend = _mods.lower_bound( root + (char)254 );
StringBuilder buf(root.size() + 2 );
buf << root << (char)255;
ModStateHolder::iterator mend = _mods.lower_bound( buf.str() );
set<string> onedownseen;
while ( e.type() && m != mend ){

View File

@ -319,6 +319,9 @@ namespace BasicTests {
class LexNumCmp {
public:
void run() {
ASSERT( ! isNumber( (char)255 ) );
ASSERT_EQUALS( 0, lexNumCmp( "a", "a" ) );
ASSERT_EQUALS( -1, lexNumCmp( "a", "aa" ) );
ASSERT_EQUALS( 1, lexNumCmp( "aa", "a" ) );
@ -346,7 +349,7 @@ namespace BasicTests {
ASSERT_EQUALS( -1, lexNumCmp( "f12f", "f12g" ) );
ASSERT_EQUALS( 1, lexNumCmp( "f12g", "f12f" ) );
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aab" ) );
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aa1" ) );
ASSERT_EQUALS( -1, lexNumCmp( "aa{", "aa1" ) );
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a11" ) );
ASSERT_EQUALS( 1, lexNumCmp( "a1{a", "a1{" ) );
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) );
@ -355,6 +358,10 @@ namespace BasicTests {
ASSERT_EQUALS( -1 , lexNumCmp( "a.0" , "a.1" ) );
ASSERT_EQUALS( -1 , lexNumCmp( "a.0.b" , "a.1" ) );
ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.|" ) );
ASSERT_EQUALS( -1 , lexNumCmp( "b.0e" , (string("b.") + (char)255).c_str() ) );
ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.0e" ) );
}
};

View File

@ -652,15 +652,17 @@ namespace mongo {
// for convenience, '{' is greater than anything and stops number parsing
inline int lexNumCmp( const char *s1, const char *s2 ) {
//cout << "START : " << s1 << "\t" << s2 << endl;
while( *s1 && *s2 ) {
bool p1 = ( *s1 == '{' );
bool p2 = ( *s2 == '{' );
bool p1 = ( *s1 == (char)255 );
bool p2 = ( *s2 == (char)255 );
//cout << "\t\t " << p1 << "\t" << p2 << endl;
if ( p1 && !p2 )
return 1;
if ( p2 && !p1 )
return -1;
bool n1 = isNumber( *s1 );
bool n2 = isNumber( *s2 );