From bef9177e79b57127765e90730471139ee31c0d69 Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@alchemyviewer.org> Date: Sun, 4 Jul 2021 17:31:03 -0400 Subject: [PATCH] Clean up llxml loops and strings --- indra/llxml/llxmlnode.cpp | 46 +++++++++++++++++---------------------- indra/llxml/llxmlnode.h | 3 +-- indra/llxml/llxmltree.cpp | 29 +++++++++++++----------- indra/llxml/llxmltree.h | 4 ++-- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/indra/llxml/llxmlnode.cpp b/indra/llxml/llxmlnode.cpp index 3e0951ef32c..4c260935490 100644 --- a/indra/llxml/llxmlnode.cpp +++ b/indra/llxml/llxmlnode.cpp @@ -144,17 +144,15 @@ LLXMLNodePtr LLXMLNode::deepCopy() LLXMLNodePtr newnode = LLXMLNodePtr(new LLXMLNode(*this)); if (mChildren.notNull()) { - for (LLXMLChildList::iterator iter = mChildren->map.begin(); - iter != mChildren->map.end(); ++iter) - { - LLXMLNodePtr temp_ptr_for_gcc(iter->second->deepCopy()); + for (auto& map_pair : mChildren->map) + { + LLXMLNodePtr temp_ptr_for_gcc(map_pair.second->deepCopy()); newnode->addChild(temp_ptr_for_gcc); } } - for (LLXMLAttribList::iterator iter = mAttributes.begin(); - iter != mAttributes.end(); ++iter) - { - LLXMLNodePtr temp_ptr_for_gcc(iter->second->deepCopy()); + for (auto& attrib_pair : mAttributes) + { + LLXMLNodePtr temp_ptr_for_gcc(attrib_pair.second->deepCopy()); newnode->addChild(temp_ptr_for_gcc); } @@ -170,10 +168,9 @@ LLXMLNode::~LLXMLNode() // mess. if (mChildren.notNull()) { - for (LLXMLChildList::iterator iter = mChildren->map.begin(); - iter != mChildren->map.end(); ++iter) - { - LLXMLNodePtr child = iter->second; + for (auto& map_pair : mChildren->map) + { + LLXMLNodePtr child = map_pair.second; child->mParent = NULL; child->mNext = NULL; child->mPrev = NULL; @@ -183,10 +180,9 @@ LLXMLNode::~LLXMLNode() mChildren->tail = NULL; mChildren = NULL; } - for (LLXMLAttribList::iterator iter = mAttributes.begin(); - iter != mAttributes.end(); ++iter) - { - LLXMLNodePtr attr = iter->second; + for (auto& attrib_pair : mAttributes) + { + LLXMLNodePtr attr = attrib_pair.second; attr->mParent = NULL; attr->mNext = NULL; attr->mPrev = NULL; @@ -290,7 +286,7 @@ void LLXMLNode::addChild(LLXMLNodePtr& new_child) mChildren->head = new_child; mChildren->tail = new_child; } - mChildren->map.insert(std::make_pair(new_child->mName, new_child)); + mChildren->map.emplace(new_child->mName, new_child); if (mChildren->tail != new_child) { @@ -511,10 +507,9 @@ void XMLCALL EndXMLNode(void *userData, { std::string value = node->getValue(); BOOL is_empty = TRUE; - for (std::string::size_type s = 0; s < value.length(); s++) - { - char c = value[s]; - if (c != ' ' && c != '\t' && c != '\n') + for (char c : value) + { + if (c != ' ' && c != '\t' && c != '\n') { is_empty = FALSE; break; @@ -1204,7 +1199,7 @@ void LLXMLNode::getChildren(const LLStringTableEntry* name, LLXMLNodeList &child } } } - if (children.size() == 0 && use_default_if_missing && !mDefault.isNull()) + if (children.empty() && use_default_if_missing && !mDefault.isNull()) { mDefault->getChildren(name, children, FALSE); } @@ -1215,10 +1210,9 @@ void LLXMLNode::getDescendants(const LLStringTableEntry* name, LLXMLNodeList &ch { if (mChildren.notNull()) { - for (LLXMLChildList::const_iterator child_itr = mChildren->map.begin(); - child_itr != mChildren->map.end(); ++child_itr) - { - LLXMLNodePtr child = (*child_itr).second; + for (const auto& child_itr : mChildren->map) + { + LLXMLNodePtr child = child_itr.second; if (name == child->mName) { children.insert(std::make_pair(child->mName->mString, child)); diff --git a/indra/llxml/llxmlnode.h b/indra/llxml/llxmlnode.h index b6c5845cb01..1a8f3b9484d 100644 --- a/indra/llxml/llxmlnode.h +++ b/indra/llxml/llxmlnode.h @@ -210,8 +210,7 @@ class LLXMLNode : public LLThreadSafeRefCount std::string getSanitizedValue() const; std::string getTextContents() const; const LLStringTableEntry* getName() const { return mName; } - BOOL hasName(const char* name) const { return mName == gStringTable.checkStringEntry(name); } - BOOL hasName(const std::string& name) const { return mName == gStringTable.checkStringEntry(name.c_str()); } + BOOL hasName(std::string_view name) const { return mName == gStringTable.checkStringEntry(name); } const std::string& getID() const { return mID; } U32 getChildCount() const; diff --git a/indra/llxml/llxmltree.cpp b/indra/llxml/llxmltree.cpp index 851ad17043b..e3f43b202e3 100644 --- a/indra/llxml/llxmltree.cpp +++ b/indra/llxml/llxmltree.cpp @@ -99,8 +99,8 @@ void LLXmlTree::dumpNode( LLXmlTreeNode* node, const std::string& prefix ) ////////////////////////////////////////////////////////////// // LLXmlTreeNode -LLXmlTreeNode::LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LLXmlTree* tree ) - : mName(name), +LLXmlTreeNode::LLXmlTreeNode(std::string name, LLXmlTreeNode* parent, LLXmlTree* tree ) + : mName(std::move(name)), mParent(parent), mTree(tree) { @@ -108,16 +108,19 @@ LLXmlTreeNode::LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LL LLXmlTreeNode::~LLXmlTreeNode() { - attribute_map_t::iterator iter; - for (iter=mAttributes.begin(); iter != mAttributes.end(); iter++) - delete iter->second; - for(LLXmlTreeNode* node : mChildren) - { - delete node; - } - mChildren.clear(); -} - + for (auto& attrib_pair : mAttributes) + { + delete attrib_pair.second; + } + mAttributes.clear(); + + for (LLXmlTreeNode* node : mChildren) + { + delete node; + } + mChildren.clear(); +} + void LLXmlTreeNode::dump( const std::string& prefix ) { LL_INFOS() << prefix << mName ; @@ -548,7 +551,7 @@ BOOL LLXmlTreeParser::parseFile(const std::string &path, LLXmlTreeNode** root, B const std::string& LLXmlTreeParser::tabs() { static std::string s; - s = ""; + s.clear(); S32 num_tabs = getDepth() - 1; for( S32 i = 0; i < num_tabs; i++) { diff --git a/indra/llxml/llxmltree.h b/indra/llxml/llxmltree.h index 5a0c437a346..407fb7055e7 100644 --- a/indra/llxml/llxmltree.h +++ b/indra/llxml/llxmltree.h @@ -89,7 +89,7 @@ class LLXmlTreeNode protected: // Protected since nodes are only created and destroyed by friend classes and other LLXmlTreeNodes - LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LLXmlTree* tree ); + LLXmlTreeNode(std::string name, LLXmlTreeNode* parent, LLXmlTree* tree ); public: virtual ~LLXmlTreeNode(); @@ -98,7 +98,7 @@ class LLXmlTreeNode { return mName; } - BOOL hasName( const std::string& name ) + BOOL hasName( std::string_view name ) { return mName == name; } -- GitLab