Skip to content
Browse files

Pointer and ref go with type, not with identifier. Made it consistenl…

…y in update module.
  • Loading branch information...
1 parent 2b2892f commit c9819685b10108ed14aa4efc886950bf8b78a3c9 Alberto Lerner committed May 11, 2012
Showing with 67 additions and 69 deletions.
  1. +34 −34 src/mongo/db/ops/update.cpp
  2. +33 −35 src/mongo/db/ops/update.h
View
68 src/mongo/db/ops/update.cpp
@@ -84,11 +84,11 @@ namespace mongo {
}
template< class Builder >
- void appendUnset( Builder &b ) {
+ void appendUnset( Builder& b ) {
}
template<>
- void appendUnset( BSONArrayBuilder &b ) {
+ void appendUnset( BSONArrayBuilder& b ) {
b.appendNull();
}
@@ -340,8 +340,8 @@ namespace mongo {
// -1 inside a non-object (non-object could be array)
// 0 missing
// 1 found
- int validRenamePath( BSONObj obj, const char *path ) {
- while( const char *p = strchr( path, '.' ) ) {
+ int validRenamePath( BSONObj obj, const char* path ) {
+ while( const char* p = strchr( path, '.' ) ) {
string left( path, p - path );
BSONElement e = obj.getField( left );
if ( e.eoo() ) {
@@ -356,7 +356,7 @@ namespace mongo {
return !obj.getField( path ).eoo();
}
- auto_ptr<ModSetState> ModSet::prepare(const BSONObj &obj) const {
+ auto_ptr<ModSetState> ModSet::prepare(const BSONObj& obj) const {
DEBUGUPDATE( "\t start prepare" );
auto_ptr<ModSetState> mss( new ModSetState( obj ) );
@@ -523,7 +523,7 @@ namespace mongo {
return;
}
- const char * name = fixedOpName ? fixedOpName : Mod::modNames[op()];
+ const char* name = fixedOpName ? fixedOpName : Mod::modNames[op()];
DEBUGUPDATE( "\t\t\t\t\t appendForOpLog name:" << name << " fixed: " << fixed << " fn: " << m->fieldName );
@@ -547,7 +547,7 @@ namespace mongo {
}
template< class Builder >
- void ModState::handleRename( Builder &newObjBuilder, const char *shortFieldName ) {
+ void ModState::handleRename( Builder& newObjBuilder, const char* shortFieldName ) {
newObjBuilder.appendAs( newVal , shortFieldName );
BSONObjBuilder b;
b.appendAs( newVal, shortFieldName );
@@ -606,9 +606,9 @@ namespace mongo {
template< class Builder >
void ModSetState::_appendNewFromMods( const string& root , ModState& m , Builder& b ,
set<string>& onedownseen ) {
- const char * temp = m.fieldName();
+ const char* temp = m.fieldName();
temp += root.size();
- const char * dot = strchr( temp , '.' );
+ const char* dot = strchr( temp , '.' );
if ( dot ) {
string nr( m.fieldName() , 0 , 1 + ( dot - m.fieldName() ) );
string nf( temp , 0 , dot - temp );
@@ -625,30 +625,30 @@ namespace mongo {
}
}
- bool ModSetState::duplicateFieldName( const BSONElement &a, const BSONElement &b ) {
+ bool ModSetState::duplicateFieldName( const BSONElement& a, const BSONElement& b ) {
return
!a.eoo() &&
!b.eoo() &&
( a.rawdata() != b.rawdata() ) &&
str::equals( a.fieldName(), b.fieldName() );
}
- ModSetState::ModStateRange ModSetState::modsForRoot( const string &root ) {
+ ModSetState::ModStateRange ModSetState::modsForRoot( const string& root ) {
ModStateHolder::iterator mstart = _mods.lower_bound( root );
StringBuilder buf;
buf << root << (char)255;
ModStateHolder::iterator mend = _mods.lower_bound( buf.str() );
return make_pair( mstart, mend );
}
- void ModSetState::createNewObjFromMods( const string &root , BSONObjBuilder &b ,
- const BSONObj &obj ) {
+ void ModSetState::createNewObjFromMods( const string& root , BSONObjBuilder& b ,
+ const BSONObj& obj ) {
BSONObjIteratorSorted es( obj );
createNewFromMods( root, b, es, modsForRoot( root ), LexNumCmp( true ) );
}
- void ModSetState::createNewArrayFromMods( const string &root , BSONArrayBuilder &b ,
- const BSONArray &arr ) {
+ void ModSetState::createNewArrayFromMods( const string& root , BSONArrayBuilder& b ,
+ const BSONArray& arr ) {
BSONArrayIteratorSorted es( arr );
ModStateRange objectOrderedRange = modsForRoot( root );
ModStateHolder arrayOrderedMods( LexNumCmp( false ) );
@@ -810,16 +810,16 @@ namespace mongo {
NOTE: MODIFIES source from object!
*/
ModSet::ModSet(
- const BSONObj &from ,
+ const BSONObj& from ,
const set<string>& idxKeys,
- const set<string> *backgroundKeys)
+ const set<string>* backgroundKeys)
: _isIndexed(0) , _hasDynamicArray( false ) {
BSONObjIterator it(from);
while ( it.more() ) {
BSONElement e = it.next();
- const char *fn = e.fieldName();
+ const char* fn = e.fieldName();
uassert( 10147 , "Invalid modifier specified: " + string( fn ), e.type() == Object );
BSONObj j = e.embeddedObject();
@@ -831,7 +831,7 @@ namespace mongo {
while ( jt.more() ) {
BSONElement f = jt.next(); // x:44
- const char * fieldName = f.fieldName();
+ const char* fieldName = f.fieldName();
uassert( 15896 , "Modified field name may not start with $", fieldName[0] != '$' || op == Mod::UNSET ); // allow remove of invalid field name in case it was inserted before this check was added (~ version 2.1)
uassert( 10148 , "Mod on _id not allowed", strcmp( fieldName, "_id" ) != 0 );
@@ -843,7 +843,7 @@ namespace mongo {
if ( op == Mod::RENAME_TO ) {
uassert( 13494, "$rename target must be a string", f.type() == String );
- const char *target = f.valuestr();
+ const char* target = f.valuestr();
uassert( 13495, "$rename source must differ from target", strcmp( fieldName, target ) != 0 );
uassert( 13496, "invalid mod field name, source may not be empty", fieldName[0] );
uassert( 13479, "invalid mod field name, target may not be empty", target[0] );
@@ -887,8 +887,8 @@ namespace mongo {
}
- ModSet * ModSet::fixDynamicArray( const string &elemMatchKey ) const {
- ModSet * n = new ModSet();
+ ModSet* ModSet::fixDynamicArray( const string& elemMatchKey ) const {
+ ModSet* n = new ModSet();
n->_isIndexed = _isIndexed;
n->_hasDynamicArray = _hasDynamicArray;
for ( ModHolder::const_iterator i=_mods.begin(); i!=_mods.end(); i++ ) {
@@ -931,12 +931,12 @@ namespace mongo {
*/
static UpdateResult _updateById(bool isOperatorUpdate,
int idIdxNo,
- ModSet *mods,
+ ModSet* mods,
int profile,
- NamespaceDetails *d,
+ NamespaceDetails* d,
NamespaceDetailsTransient *nsdt,
bool su,
- const char *ns,
+ const char* ns,
const BSONObj& updateobj,
BSONObj patternOrig,
bool logop,
@@ -953,7 +953,7 @@ namespace mongo {
return UpdateResult(0, 0, 0);
}
}
- Record *r = loc.rec();
+ Record* r = loc.rec();
if ( cc().allowedToThrowPageFaultException() && ! r->likelyInPhysicalMemory() ) {
throw PageFaultException( r );
@@ -1011,7 +1011,7 @@ namespace mongo {
}
UpdateResult _updateObjects( bool su,
- const char *ns,
+ const char* ns,
const BSONObj& updateobj,
BSONObj patternOrig,
bool upsert,
@@ -1020,7 +1020,7 @@ namespace mongo {
OpDebug& debug,
RemoveSaver* rs,
bool fromMigrate,
- const QueryPlanSelectionPolicy &planPolicy ) {
+ const QueryPlanSelectionPolicy& planPolicy ) {
DEBUGUPDATE( "update: " << ns << " update: " << updateobj << " query: " << patternOrig << " upsert: " << upsert << " multi: " << multi );
Client& client = cc();
int profile = client.database()->profile;
@@ -1029,8 +1029,8 @@ namespace mongo {
// idea with these here it to make them loop invariant for multi updates, and thus be a bit faster for that case
// The pointers may be left invalid on a failed or terminal yield recovery.
- NamespaceDetails *d = nsdetails(ns); // can be null if an upsert...
- NamespaceDetailsTransient *nsdt = &NamespaceDetailsTransient::get(ns);
+ NamespaceDetails* d = nsdetails(ns); // can be null if an upsert...
+ NamespaceDetailsTransient* nsdt = &NamespaceDetailsTransient::get(ns);
auto_ptr<ModSet> mods;
bool isOperatorUpdate = updateobj.firstElementFieldName()[0] == '$';
@@ -1145,7 +1145,7 @@ namespace mongo {
continue;
}
- Record *r = c->_current();
+ Record* r = c->_current();
DiskLoc loc = c->currLoc();
if ( c->getsetdup( loc ) && autoDedup ) {
@@ -1185,7 +1185,7 @@ namespace mongo {
const BSONObj& onDisk = loc.obj();
- ModSet * useMods = mods.get();
+ ModSet* useMods = mods.get();
bool forceRewrite = false;
auto_ptr<ModSet> mymodset;
@@ -1321,15 +1321,15 @@ namespace mongo {
return UpdateResult( 0 , isOperatorUpdate , 0 );
}
- UpdateResult updateObjects( const char *ns,
+ UpdateResult updateObjects( const char* ns,
const BSONObj& updateobj,
BSONObj patternOrig,
bool upsert,
bool multi,
bool logop ,
OpDebug& debug,
bool fromMigrate,
- const QueryPlanSelectionPolicy &planPolicy ) {
+ const QueryPlanSelectionPolicy& planPolicy ) {
uassert( 10155 , "cannot update reserved $ collection", strchr(ns, '$') == 0 );
if ( strstr(ns, ".system.") ) {
/* dm: it's very important that system.indexes is never updated as IndexDetails has pointers into it */
View
68 src/mongo/db/ops/update.h
@@ -48,29 +48,27 @@ namespace mongo {
multi - update multiple objects - mostly useful with things like $set
su - allow access to system namespaces (super user)
*/
- UpdateResult updateObjects(const char *ns,
+ UpdateResult updateObjects(const char* ns,
const BSONObj& updateobj,
BSONObj pattern,
bool upsert,
- bool multi ,
- bool logop ,
+ bool multi,
+ bool logop,
OpDebug& debug,
bool fromMigrate = false,
- const QueryPlanSelectionPolicy &planPolicy =
- QueryPlanSelectionPolicy::any());
+ const QueryPlanSelectionPolicy& planPolicy = QueryPlanSelectionPolicy::any());
UpdateResult _updateObjects(bool su,
- const char *ns,
+ const char* ns,
const BSONObj& updateobj,
BSONObj pattern,
bool upsert,
- bool multi ,
- bool logop ,
- OpDebug& debug ,
- RemoveSaver * rs = 0,
+ bool multi,
+ bool logop,
+ OpDebug& debug,
+ RemoveSaver* rs = 0,
bool fromMigrate = false,
- const QueryPlanSelectionPolicy &planPolicy =
- QueryPlanSelectionPolicy::any());
+ const QueryPlanSelectionPolicy& planPolicy = QueryPlanSelectionPolicy::any());
// ---------- private -------------
@@ -89,8 +87,8 @@ namespace mongo {
static const char* modNames[];
static unsigned modNamesNum;
- const char *fieldName;
- const char *shortFieldName;
+ const char* fieldName;
+ const char* shortFieldName;
BSONElement elt; // x:5 note: this is the actual element from the updateobj
boost::shared_ptr<Matcher> matcher;
@@ -112,7 +110,7 @@ namespace mongo {
}
}
- void setFieldName( const char * s ) {
+ void setFieldName( const char* s ) {
fieldName = s;
shortFieldName = strrchr( fieldName , '.' );
if ( shortFieldName )
@@ -160,7 +158,7 @@ namespace mongo {
template< class Builder >
void appendIncremented( Builder& bb , const BSONElement& in, ModState& ms ) const;
- bool operator<( const Mod &other ) const {
+ bool operator<( const Mod& other ) const {
return strcmp( fieldName, other.fieldName ) < 0;
}
@@ -178,7 +176,7 @@ namespace mongo {
static bool isIndexed( const string& fullName , const set<string>& idxKeys ) {
const char * fieldName = fullName.c_str();
// check if there is an index key that is a parent of mod
- for( const char *dot = strchr( fieldName, '.' ); dot; dot = strchr( dot + 1, '.' ) )
+ for( const char* dot = strchr( fieldName, '.' ); dot; dot = strchr( dot + 1, '.' ) )
if ( idxKeys.count( string( fieldName, dot - fieldName ) ) )
return true;
@@ -282,7 +280,7 @@ namespace mongo {
}
}
- const char *renameFrom() const {
+ const char* renameFrom() const {
massert( 13492, "mod must be RENAME_TO type", op == Mod::RENAME_TO );
return elt.fieldName();
}
@@ -298,7 +296,7 @@ namespace mongo {
int _isIndexed;
bool _hasDynamicArray;
- static Mod::Op opFromStr( const char *fn ) {
+ static Mod::Op opFromStr( const char* fn ) {
verify( fn[0] == '$' );
switch( fn[1] ) {
case 'i': {
@@ -369,7 +367,7 @@ namespace mongo {
ModSet() {}
- void updateIsIndexed( const Mod &m, const set<string> &idxKeys, const set<string> *backgroundKeys ) {
+ void updateIsIndexed( const Mod& m, const set<string>& idxKeys, const set<string>* backgroundKeys ) {
if ( m.isIndexed( idxKeys ) ||
(backgroundKeys && m.isIndexed(*backgroundKeys)) ) {
_isIndexed++;
@@ -378,13 +376,13 @@ namespace mongo {
public:
- ModSet( const BSONObj &from ,
+ ModSet( const BSONObj& from ,
const set<string>& idxKeys = set<string>(),
const set<string>* backgroundKeys = 0
);
// TODO: this is inefficient - should probably just handle when iterating
- ModSet * fixDynamicArray( const string &elemMatchKey ) const;
+ ModSet * fixDynamicArray( const string& elemMatchKey ) const;
bool hasDynamicArray() const { return _hasDynamicArray; }
@@ -409,7 +407,7 @@ namespace mongo {
unsigned size() const { return _mods.size(); }
- bool haveModForField( const char *fieldName ) const {
+ bool haveModForField( const char* fieldName ) const {
return _mods.find( fieldName ) != _mods.end();
}
@@ -442,13 +440,13 @@ namespace mongo {
*/
class ModState : boost::noncopyable {
public:
- const Mod * m;
+ const Mod* m;
BSONElement old;
BSONElement newVal;
BSONObj _objData;
- const char * fixedOpName;
- BSONElement * fixed;
+ const char* fixedOpName;
+ BSONElement* fixed;
int pushStartSize;
BSONType incType;
@@ -470,7 +468,7 @@ namespace mongo {
return m->op;
}
- const char * fieldName() const {
+ const char* fieldName() const {
return m->fieldName;
}
@@ -504,7 +502,7 @@ namespace mongo {
template< class Builder >
void appendIncValue( Builder& b , bool useFullName ) const {
- const char * n = useFullName ? m->fieldName : m->shortFieldName;
+ const char* n = useFullName ? m->fieldName : m->shortFieldName;
switch ( incType ) {
case NumberDouble:
@@ -521,7 +519,7 @@ namespace mongo {
string toString() const;
template< class Builder >
- void handleRename( Builder &newObjBuilder, const char *shortFieldName );
+ void handleRename( Builder& newObjBuilder, const char* shortFieldName );
};
/**
@@ -549,11 +547,11 @@ namespace mongo {
return _inPlacePossible;
}
- ModStateRange modsForRoot( const string &root );
+ ModStateRange modsForRoot( const string& root );
- void createNewObjFromMods( const string &root, BSONObjBuilder &b, const BSONObj &obj );
- void createNewArrayFromMods( const string &root, BSONArrayBuilder &b,
- const BSONArray &arr );
+ void createNewObjFromMods( const string& root, BSONObjBuilder& b, const BSONObj& obj );
+ void createNewArrayFromMods( const string& root, BSONArrayBuilder& b,
+ const BSONArray& arr );
template< class Builder >
void createNewFromMods( const string& root , Builder& b , BSONIteratorSorted& es ,
@@ -639,7 +637,7 @@ namespace mongo {
}
/** @return true iff the elements aren't eoo(), are distinct, and share a field name. */
- static bool duplicateFieldName( const BSONElement &a, const BSONElement &b );
+ static bool duplicateFieldName( const BSONElement& a, const BSONElement& b );
public:
@@ -678,7 +676,7 @@ namespace mongo {
return false;
}
- void appendSizeSpecForArrayDepMods( BSONObjBuilder &b ) const {
+ void appendSizeSpecForArrayDepMods( BSONObjBuilder& b ) const {
for ( ModStateHolder::const_iterator i = _mods.begin(); i != _mods.end(); i++ ) {
const ModState& m = *i->second;
if ( m.m->arrayDep() ) {

0 comments on commit c981968

Please sign in to comment.
Something went wrong with that request. Please try again.