optimize: take CString&, not char*; passing char* causes a CString to be

constructed from it when we use it, which is a waste, since it often comes from
a CString already
cleanup
This commit is contained in:
Glenn Maynard
2005-09-04 05:12:48 +00:00
parent 6149d63867
commit 286c008b41
2 changed files with 50 additions and 77 deletions
+21 -45
View File
@@ -632,14 +632,6 @@ XAttr *XNode::GetAttr( const CString &attrname )
return NULL; return NULL;
} }
// Desc : get attribute with attribute name, return its value
const char* XNode::GetAttrValue( const CString &attrname )
{
XAttr *attr = GetAttr( attrname );
return attr ? (const char*)attr->m_sValue : NULL;
}
// get child node count // get child node count
int XNode::GetChildCount() const int XNode::GetChildCount() const
{ {
@@ -648,9 +640,9 @@ int XNode::GetChildCount() const
// Desc : Find child with name and return child // Desc : Find child with name and return child
// Return : NULL return if no child. // Return : NULL return if no child.
XNode *XNode::GetChild( const char* name ) XNode *XNode::GetChild( const CString &sName )
{ {
multimap<CString, XNode*>::iterator it = m_childs.find( name ); multimap<CString, XNode*>::iterator it = m_childs.find( sName );
if( it != m_childs.end() ) if( it != m_childs.end() )
{ {
DEBUG_ASSERT( name == it->second->m_sName ); DEBUG_ASSERT( name == it->second->m_sName );
@@ -659,9 +651,9 @@ XNode *XNode::GetChild( const char* name )
return NULL; return NULL;
} }
const XNode *XNode::GetChild( const char* name ) const const XNode *XNode::GetChild( const CString &sName ) const
{ {
multimap<CString, XNode*>::const_iterator it = m_childs.find( name ); multimap<CString, XNode*>::const_iterator it = m_childs.find( sName );
if( it != m_childs.end() ) if( it != m_childs.end() )
{ {
DEBUG_ASSERT( name == it->second->m_sName ); DEBUG_ASSERT( name == it->second->m_sName );
@@ -670,32 +662,17 @@ const XNode *XNode::GetChild( const char* name ) const
return NULL; return NULL;
} }
// Desc : Find child with name and return child's value
// Return : NULL return if no child.
const char* XNode::GetChildValue( const char* name )
{
XNode *node = GetChild( name );
return (node != NULL)? (const char*)node->m_sValue : NULL;
}
XAttr *XNode::GetChildAttr( const char* name, const char* attrname ) XAttr *XNode::GetChildAttr( const char* name, const char* attrname )
{ {
XNode *node = GetChild(name); XNode *node = GetChild(name);
return node ? node->GetAttr(attrname) : NULL; return node ? node->GetAttr(attrname) : NULL;
} }
const char* XNode::GetChildAttrValue( const char* name, const char* attrname ) XNode *XNode::AppendChild( const CString &sName, const char* value ) { XNode *p = new XNode; p->m_sName = sName; p->m_sValue = value; return AppendChild( p ); }
{ XNode *XNode::AppendChild( const CString &sName, float value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
XAttr *attr = GetChildAttr( name, attrname ); XNode *XNode::AppendChild( const CString &sName, int value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
return attr ? (const char*)attr->m_sValue : NULL; XNode *XNode::AppendChild( const CString &sName, unsigned value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
} XNode *XNode::AppendChild( const CString &sName, const DateTime &value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, const char* value ) { XNode *p = new XNode; p->m_sName = name; p->m_sValue = value; return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, float value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, int value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, unsigned value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, const DateTime &value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( XNode *node ) XNode *XNode::AppendChild( XNode *node )
{ {
@@ -743,26 +720,25 @@ bool XNode::RemoveAttr( XAttr *attr )
return false; return false;
} }
XAttr *XNode::AppendAttr( const char* name /*= NULL*/, const char* value /*= NULL*/ ) XAttr *XNode::AppendAttr( const CString &sName, const CString &sValue )
{ {
XAttr *attr = new XAttr; XAttr *pAttr = new XAttr;
attr->m_sName = name; pAttr->m_sName = sName;
attr->m_sValue = value; pAttr->m_sValue = sValue;
return AppendAttr( attr ); return AppendAttr( pAttr );
} }
XAttr *XNode::AppendAttr( const char* name, float value ){ return AppendAttr(name,ssprintf("%f",value)); } XAttr *XNode::AppendAttr( const CString &sName, float value ){ return AppendAttr(sName,ssprintf("%f",value)); }
XAttr *XNode::AppendAttr( const char* name, int value ) { return AppendAttr(name,ssprintf("%d",value)); } XAttr *XNode::AppendAttr( const CString &sName, int value ) { return AppendAttr(sName,ssprintf("%d",value)); }
XAttr *XNode::AppendAttr( const char* name, unsigned value ) { return AppendAttr(name,ssprintf("%u",value)); } XAttr *XNode::AppendAttr( const CString &sName, unsigned value ) { return AppendAttr(sName,ssprintf("%u",value)); }
// Desc : add attribute void XNode::SetAttrValue( const CString &sName, const CString &sValue )
void XNode::SetAttrValue( const char* name, const char* value )
{ {
XAttr* pAttr = GetAttr( name ); XAttr* pAttr = GetAttr( sName );
if( pAttr ) if( pAttr )
pAttr->m_sValue = value; pAttr->m_sValue = sValue;
else else
AppendAttr( name, value ); AppendAttr( sName, sValue );
} }
+29 -32
View File
@@ -177,50 +177,47 @@ struct XNode
bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const; bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const;
// in own attribute list // in own attribute list
const XAttr *GetAttr( const CString &attrname ) const; const XAttr *GetAttr( const CString &sAttrName ) const;
XAttr *GetAttr( const CString &attrname ); XAttr *GetAttr( const CString &sAttrName );
const char* GetAttrValue( const CString &attrname ); bool GetAttrValue( const CString &sName, CString &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, CString &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue( const CString &sName, int &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, int &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue( const CString &sName, float &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, float &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue( const CString &sName, bool &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, bool &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue( const CString &sName, unsigned &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, unsigned &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue( const CString &sName, DateTime &out ) const { const XAttr* pAttr=GetAttr(sName); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue( const char* name, DateTime &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
// in one level child nodes // in one level child nodes
const XNode *GetChild( const char* m_sName ) const; const XNode *GetChild( const CString &sName ) const;
XNode *GetChild( const char* m_sName ); XNode *GetChild( const CString &sName );
const char* GetChildValue( const char* m_sName ); bool GetChildValue( const CString &sName, CString &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, CString &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, int &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, int &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, float &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, float &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, bool &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, bool &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, unsigned &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, unsigned &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, DateTime &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const char* name, DateTime &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
XAttr *GetChildAttr( const char* name, const char* attrname ); XAttr *GetChildAttr( const char* name, const char* attrname );
const char* GetChildAttrValue( const char* name, const char* attrname );
// modify DOM // modify DOM
int GetChildCount() const; int GetChildCount() const;
XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL ); XNode *AppendChild( const CString &sName = "", const char* value = "" );
XNode *AppendChild( const char* m_sName, float value ); XNode *AppendChild( const CString &sName, float value );
XNode *AppendChild( const char* m_sName, int value ); XNode *AppendChild( const CString &sName, int value );
XNode *AppendChild( const char* m_sName, unsigned value ); XNode *AppendChild( const CString &sName, unsigned value );
XNode *AppendChild( const char* m_sName, const DateTime &value ); XNode *AppendChild( const CString &sName, const DateTime &value );
XNode *AppendChild( XNode *node ); XNode *AppendChild( XNode *node );
bool RemoveChild( XNode *node ); bool RemoveChild( XNode *node );
XAttr *AppendAttr( const char* m_sName = NULL, const char* value = NULL ); XAttr *AppendAttr( const CString &sName = "", const CString &sValue = "" );
XAttr *AppendAttr( const char* m_sName, float value ); XAttr *AppendAttr( const CString &sName, float value );
XAttr *AppendAttr( const char* m_sName, int value ); XAttr *AppendAttr( const CString &sName, int value );
XAttr *AppendAttr( const char* m_sName, unsigned value ); XAttr *AppendAttr( const CString &sName, unsigned value );
XAttr *AppendAttr( const char* m_sName, const DateTime &value ); XAttr *AppendAttr( const CString &sName, const DateTime &value );
XAttr *AppendAttr( XAttr *attr ); XAttr *AppendAttr( XAttr *pAttr );
bool RemoveAttr( XAttr *attr ); bool RemoveAttr( XAttr *pAttr );
// creates the attribute if it doesn't already exist // creates the attribute if it doesn't already exist
void SetAttrValue( const char* m_sName, const char* value ); void SetAttrValue( const CString &sName, const CString &sValue );
XNode() { } XNode() { }
~XNode(); ~XNode();