diff options
author | Alberto Lerner <alerner@10gen.com> | 2010-08-18 18:12:31 -0400 |
---|---|---|
committer | Alberto Lerner <alerner@10gen.com> | 2010-08-18 18:12:31 -0400 |
commit | 7a7cc4adfaa9e8647c8e51f9ff69c7cfd24038e8 (patch) | |
tree | fc088a22f4fa7a1ceccace48ea23e5b46d9c6ef0 | |
parent | 3a455a39abbb08d906e1996d206c93b5e26741d7 (diff) | |
download | mongo-7a7cc4adfaa9e8647c8e51f9ff69c7cfd24038e8.tar.gz |
SERVER-1452 StringData-ing up, c_str()-ing down
-rw-r--r-- | bson/bsonobjbuilder.h | 45 | ||||
-rw-r--r-- | client/connpool.cpp | 2 | ||||
-rw-r--r-- | client/dbclient.cpp | 6 | ||||
-rw-r--r-- | client/parallel.cpp | 2 | ||||
-rw-r--r-- | db/dbcommands_generic.cpp | 2 | ||||
-rw-r--r-- | db/geo/2d.cpp | 2 | ||||
-rw-r--r-- | db/json.cpp | 5 | ||||
-rw-r--r-- | db/mr.cpp | 2 | ||||
-rw-r--r-- | db/stats/top.cpp | 2 | ||||
-rw-r--r-- | db/update.cpp | 2 | ||||
-rw-r--r-- | s/commands_public.cpp | 2 | ||||
-rw-r--r-- | scripting/engine.cpp | 2 | ||||
-rw-r--r-- | scripting/engine_spidermonkey.cpp | 4 | ||||
-rw-r--r-- | scripting/sm_db.cpp | 2 | ||||
-rw-r--r-- | scripting/v8_wrapper.cpp | 6 | ||||
-rw-r--r-- | tools/files.cpp | 4 | ||||
-rw-r--r-- | util/embedded_builder.h | 4 |
17 files changed, 43 insertions, 51 deletions
diff --git a/bson/bsonobjbuilder.h b/bson/bsonobjbuilder.h index fd9e9428ea3..c52f56e9c59 100644 --- a/bson/bsonobjbuilder.h +++ b/bson/bsonobjbuilder.h @@ -346,27 +346,22 @@ namespace mongo { @param regex the regular expression pattern @param regex options such as "i" or "g" */ - BSONObjBuilder& appendRegex(const StringData& fieldName, const char *regex, const char *options = "") { + BSONObjBuilder& appendRegex(const StringData& fieldName, const StringData& regex, const StringData& options = "") { _b.appendNum((char) RegEx); _b.appendStr(fieldName); _b.appendStr(regex); _b.appendStr(options); return *this; } - /** Append a regular expression value - @param regex the regular expression pattern - @param regex options such as "i" or "g" - */ - BSONObjBuilder& appendRegex(const StringData& fieldName, string regex, string options = "") { - return appendRegex(fieldName, regex.c_str(), options.c_str()); - } - BSONObjBuilder& appendCode(const StringData& fieldName, const char *code) { + + BSONObjBuilder& appendCode(const StringData& fieldName, const StringData& code) { _b.appendNum((char) Code); _b.appendStr(fieldName); - _b.appendNum((int) strlen(code)+1); + _b.appendNum((int) code.size()+1); _b.appendStr(code); return *this; } + /** Append a string element. len DOES include terminating nul */ BSONObjBuilder& append(const StringData& fieldName, const char *str, int len) { _b.appendNum((char) String); @@ -377,16 +372,17 @@ namespace mongo { } /** Append a string element */ BSONObjBuilder& append(const StringData& fieldName, const char *str) { - return append(fieldName, str, (int) strlen(str)+1); + return append(fieldName, str, (int) strlen(str)+1); } /** Append a string element */ BSONObjBuilder& append(const StringData& fieldName, string str) { return append(fieldName, str.c_str(), (int) str.size()+1); } - BSONObjBuilder& appendSymbol(const StringData& fieldName, const char *symbol) { + + BSONObjBuilder& appendSymbol(const StringData& fieldName, const StringData& symbol) { _b.appendNum((char) Symbol); _b.appendStr(fieldName); - _b.appendNum((int) strlen(symbol)+1); + _b.appendNum((int) symbol.size()+1); _b.appendStr(symbol); return *this; } @@ -435,10 +431,10 @@ namespace mongo { Append an element of the deprecated DBRef type. @deprecated */ - BSONObjBuilder& appendDBRef( const StringData& fieldName, const char *ns, const OID &oid ) { + BSONObjBuilder& appendDBRef( const StringData& fieldName, const StringData& ns, const OID &oid ) { _b.appendNum( (char) DBRef ); _b.appendStr( fieldName ); - _b.appendNum( (int) strlen( ns ) + 1 ); + _b.appendNum( (int) ns.size() + 1 ); _b.appendStr( ns ); _b.appendBuf( (void *) &oid, 12 ); return *this; @@ -482,11 +478,11 @@ namespace mongo { /** Append to the BSON object a field of type CodeWScope. This is a javascript code fragment accompanied by some scope that goes with it. */ - BSONObjBuilder& appendCodeWScope( const StringData& fieldName, const char *code, const BSONObj &scope ) { + BSONObjBuilder& appendCodeWScope( const StringData& fieldName, const StringData& code, const BSONObj &scope ) { _b.appendNum( (char) CodeWScope ); _b.appendStr( fieldName ); - _b.appendNum( ( int )( 4 + 4 + strlen( code ) + 1 + scope.objsize() ) ); - _b.appendNum( ( int ) strlen( code ) + 1 ); + _b.appendNum( ( int )( 4 + 4 + code.size() + 1 + scope.objsize() ) ); + _b.appendNum( ( int ) code.size() + 1 ); _b.appendStr( code ); _b.appendBuf( ( void * )scope.objdata(), scope.objsize() ); return *this; @@ -498,12 +494,9 @@ namespace mongo { } /* helper function -- see Query::where() for primary way to do this. */ - void appendWhere( const char *code, const BSONObj &scope ){ + void appendWhere( const StringData& code, const BSONObj &scope ){ appendCodeWScope( "$where" , code , scope ); } - void appendWhere( const string &code, const BSONObj &scope ){ - appendWhere( code.c_str(), scope ); - } /** these are the min/max when comparing, not strict min/max elements for a given type @@ -680,19 +673,19 @@ namespace mongo { return *this; } - BufBuilder &subobjStart( const char *name = "0" ) { + BufBuilder &subobjStart( const StringData& name = "0" ) { fill( name ); - return _b.subobjStart( num().c_str() ); + return _b.subobjStart( num() ); } BufBuilder &subarrayStart( const char *name ) { fill( name ); - return _b.subarrayStart( num().c_str() ); + return _b.subarrayStart( num() ); } void appendArray( const StringData& name, BSONObj subObj ) { fill( name ); - _b.appendArray( num().c_str(), subObj ); + _b.appendArray( num(), subObj ); } void appendAs( const BSONElement &e, const char *name ) { diff --git a/client/connpool.cpp b/client/connpool.cpp index b0fe824d7ba..8065a3e57d1 100644 --- a/client/connpool.cpp +++ b/client/connpool.cpp @@ -142,7 +142,7 @@ namespace mongo { BSONObjBuilder bb( b.subobjStart( "hosts" ) ); for ( map<string,PoolForHost>::iterator i=_pools.begin(); i!=_pools.end(); ++i ){ string s = i->first; - BSONObjBuilder temp( bb.subobjStart( s.c_str() ) ); + BSONObjBuilder temp( bb.subobjStart( s ) ); temp.append( "available" , (int)(i->second.pool.size()) ); temp.appendNumber( "created" , i->second.created ); temp.done(); diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 0d0d8e5a9b4..ca8803ba67a 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -384,8 +384,8 @@ namespace mongo { BSONObj DBClientWithCommands::mapreduce(const string &ns, const string &jsmapf, const string &jsreducef, BSONObj query, const string& outputcolname) { BSONObjBuilder b; b.append("mapreduce", nsGetCollection(ns)); - b.appendCode("map", jsmapf.c_str()); - b.appendCode("reduce", jsreducef.c_str()); + b.appendCode("map", jsmapf); + b.appendCode("reduce", jsreducef); if( !query.isEmpty() ) b.append("query", query); if( !outputcolname.empty() ) @@ -397,7 +397,7 @@ namespace mongo { bool DBClientWithCommands::eval(const string &dbname, const string &jscode, BSONObj& info, BSONElement& retValue, BSONObj *args) { BSONObjBuilder b; - b.appendCode("$eval", jscode.c_str()); + b.appendCode("$eval", jscode); if ( args ) b.appendArray("args", *args); bool ok = runCommand(dbname, b.done(), info); diff --git a/client/parallel.cpp b/client/parallel.cpp index dd424891c12..94909d2c0d7 100644 --- a/client/parallel.cpp +++ b/client/parallel.cpp @@ -165,7 +165,7 @@ namespace mongo { for ( map<string,list<BSONObj> >::iterator i=out.begin(); i!=out.end(); ++i ){ string shard = i->first; list<BSONObj> l = i->second; - BSONArrayBuilder y( x.subarrayStart( shard.c_str() ) ); + BSONArrayBuilder y( x.subarrayStart( shard ) ); for ( list<BSONObj>::iterator j=l.begin(); j!=l.end(); ++j ){ BSONObj temp = *j; y.append( temp ); diff --git a/db/dbcommands_generic.cpp b/db/dbcommands_generic.cpp index 627439483a8..b2ccced06d8 100644 --- a/db/dbcommands_generic.cpp +++ b/db/dbcommands_generic.cpp @@ -152,7 +152,7 @@ namespace mongo { if (i->first != c->name) continue; - BSONObjBuilder temp( b.subobjStart( c->name.c_str() ) ); + BSONObjBuilder temp( b.subobjStart( c->name ) ); { stringstream help; diff --git a/db/geo/2d.cpp b/db/geo/2d.cpp index cb9899f97a2..8785d5c992e 100644 --- a/db/geo/2d.cpp +++ b/db/geo/2d.cpp @@ -1531,7 +1531,7 @@ namespace mongo { double dis = distanceMultiplier * p._distance; totalDistance += dis; - BSONObjBuilder bb( arr.subobjStart( BSONObjBuilder::numStr( x++ ).c_str() ) ); + BSONObjBuilder bb( arr.subobjStart( BSONObjBuilder::numStr( x++ ) ) ); bb.append( "dis" , dis ); bb.append( "obj" , p._o ); bb.done(); diff --git a/db/json.cpp b/db/json.cpp index 185a8ca0290..de1b69a2805 100644 --- a/db/json.cpp +++ b/db/json.cpp @@ -342,7 +342,7 @@ namespace mongo { struct dbrefEnd { dbrefEnd( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { - b.back()->appendDBRef( b.fieldName(), b.ns.c_str(), b.oid ); + b.back()->appendDBRef( b.fieldName(), b.ns, b.oid ); } ObjectBuilder &b; }; @@ -417,8 +417,7 @@ namespace mongo { struct regexEnd { regexEnd( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { - b.back()->appendRegex( b.fieldName(), b.regex.c_str(), - b.regexOptions.c_str() ); + b.back()->appendRegex( b.fieldName(), b.regex, b.regexOptions ); } ObjectBuilder &b; }; diff --git a/db/mr.cpp b/db/mr.cpp index 8fa8d5069d9..ad3a2c6f505 100644 --- a/db/mr.cpp +++ b/db/mr.cpp @@ -636,7 +636,7 @@ namespace mongo { uassert( 10078 , "something bad happened" , shardedOutputCollection == res["result"].valuestrsafe() ); servers.insert( shard ); - shardCounts.appendAs( res["counts"] , shard.c_str() ); + shardCounts.appendAs( res["counts"] , shard ); BSONObjIterator j( res["counts"].embeddedObjectUserCheck() ); while ( j.more() ){ diff --git a/db/stats/top.cpp b/db/stats/top.cpp index 3e6526161e9..5ab257c9490 100644 --- a/db/stats/top.cpp +++ b/db/stats/top.cpp @@ -127,7 +127,7 @@ namespace mongo { void Top::append( BSONObjBuilder& b , const UsageMap& map ){ for ( UsageMap::const_iterator i=map.begin(); i!=map.end(); i++ ){ - BSONObjBuilder bb( b.subobjStart( i->first.c_str() ) ); + BSONObjBuilder bb( b.subobjStart( i->first ) ); const CollectionData& coll = i->second; diff --git a/db/update.cpp b/db/update.cpp index f9ce1f430a3..00e5d48e29a 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -502,7 +502,7 @@ namespace mongo { if ( onedownseen.count( nf ) ) return; onedownseen.insert( nf ); - BSONObjBuilder bb ( b.subobjStart( nf.c_str() ) ); + BSONObjBuilder bb ( b.subobjStart( nf ) ); createNewFromMods( nr , bb , BSONObj() ); // don't infer an array from name bb.done(); } diff --git a/s/commands_public.cpp b/s/commands_public.cpp index 3dbc8ad5112..45874531e8b 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -676,7 +676,7 @@ namespace mongo { BSONObjBuilder b( size ); int n=0; for ( set<BSONObj,BSONObjCmp>::iterator i = all.begin() ; i != all.end(); i++ ){ - b.appendAs( i->firstElement() , b.numStr( n++ ).c_str() ); + b.appendAs( i->firstElement() , b.numStr( n++ ) ); } result.appendArray( "values" , b.obj() ); diff --git a/scripting/engine.cpp b/scripting/engine.cpp index a776428a59d..91f386f0ca4 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -74,7 +74,7 @@ namespace mongo { builder.appendDate( fieldName , Date_t((unsigned long long)getNumber( scopeName )) ); break; case Code: - builder.appendCode( fieldName , getString( scopeName ).c_str() ); + builder.appendCode( fieldName , getString( scopeName ) ); break; default: stringstream temp; diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index d41c5b10d61..3480c2fd4c0 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -324,7 +324,7 @@ namespace mongo { assert( s[0] == '/' ); s = s.substr(1); string::size_type end = s.rfind( '/' ); - b.appendRegex( name , s.substr( 0 , end ).c_str() , s.substr( end + 1 ).c_str() ); + b.appendRegex( name , s.substr( 0 , end ) , s.substr( end + 1 ) ); } void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO , const TraverseStack& stack=TraverseStack() ){ @@ -368,7 +368,7 @@ namespace mongo { appendRegex( b , name , s ); } else { - b.appendCode( name , getFunctionCode( val ).c_str() ); + b.appendCode( name , getFunctionCode( val ) ); } break; } diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index 71b5b95fd42..4a359eb0510 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -1039,7 +1039,7 @@ namespace mongo { } if ( JS_InstanceOf( c->_context , o , &dbpointer_class , 0 ) ){ - b.appendDBRef( name , c->getString( o , "ns" ).c_str() , c->toOID( c->getProperty( o , "id" ) ) ); + b.appendDBRef( name , c->getString( o , "ns" ) , c->toOID( c->getProperty( o , "id" ) ) ); return true; } diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp index 0e71c9a4896..b82e01c531a 100644 --- a/scripting/v8_wrapper.cpp +++ b/scripting/v8_wrapper.cpp @@ -400,7 +400,7 @@ namespace mongo { } if ( value->IsFunction() ){ - b.appendCode( sname , toSTLString( value ).c_str() ); + b.appendCode( sname , toSTLString( value ) ); return; } @@ -453,7 +453,7 @@ namespace mongo { s = s.substr( 1 ); string r = s.substr( 0 , s.rfind( "/" ) ); string o = s.substr( s.rfind( "/" ) + 1 ); - b.appendRegex( sname , r.c_str() , o.c_str() ); + b.appendRegex( sname , r , o ); } else if ( value->ToObject()->GetPrototype()->IsObject() && value->ToObject()->GetPrototype()->ToObject()->HasRealNamedProperty( v8::String::New( "isObjectId" ) ) ){ @@ -481,7 +481,7 @@ namespace mongo { OID oid; oid.init( toSTLString( value->ToObject()->Get( v8::String::New( "id" ) ) ) ); string ns = toSTLString( value->ToObject()->Get( v8::String::New( "ns" ) ) ); - b.appendDBRef( sname, ns.c_str(), oid ); + b.appendDBRef( sname, ns, oid ); } else if ( !value->ToObject()->GetHiddenValue( v8::String::New( "__BinData" ) ).IsEmpty() ) { int len = obj->Get( v8::String::New( "len" ) )->ToInt32()->Value(); diff --git a/tools/files.cpp b/tools/files.cpp index 5adcdae82f6..0d43e08c924 100644 --- a/tools/files.cpp +++ b/tools/files.cpp @@ -87,7 +87,7 @@ public: if ( cmd == "list" ){ BSONObjBuilder b; if ( filename.size() ) - b.appendRegex( "filename" , ( (string)"^" + filename ).c_str() ); + b.appendRegex( "filename" , ( (string)"^" + filename ) ); display( &g , b.obj() ); return 0; } @@ -100,7 +100,7 @@ public: if ( cmd == "search" ){ BSONObjBuilder b; - b.appendRegex( "filename" , filename.c_str() ); + b.appendRegex( "filename" , filename ); display( &g , b.obj() ); return 0; } diff --git a/util/embedded_builder.h b/util/embedded_builder.h index 8ca47e5a7c2..71e85c7ee1b 100644 --- a/util/embedded_builder.h +++ b/util/embedded_builder.h @@ -54,7 +54,7 @@ namespace mongo { } BufBuilder &subarrayStartAs( string name ) { prepareContext( name ); - return back()->subarrayStart( name.c_str() ); + return back()->subarrayStart( name ); } void done() { while( ! _builderStorage.empty() ) @@ -72,7 +72,7 @@ namespace mongo { private: void addBuilder( const string &name ) { - shared_ptr< BSONObjBuilder > newBuilder( new BSONObjBuilder( back()->subobjStart( name.c_str() ) ) ); + shared_ptr< BSONObjBuilder > newBuilder( new BSONObjBuilder( back()->subobjStart( name ) ) ); _builders.push_back( make_pair( name, newBuilder.get() ) ); _builderStorage.push_back( newBuilder ); } |