@@ -17,6 +17,15 @@ MetadataReader::MetadataReader(uint32_t nodesLength, uint8_t* nodeData, uint32_t
1717 m_root = BuildTree ();
1818}
1919
20+ // helper debug function when need to convert a metadata node to its full name
21+ // std::string toFullName(MetadataTreeNode* p) {
22+ // std::string final = p->name;
23+ // while((p = p->parent) && !p->name.empty()) {
24+ // final.insert(0,p->name + ".");
25+ // };
26+ // return final;
27+ // }
28+
2029MetadataTreeNode* MetadataReader::BuildTree () {
2130 MetadataTreeNodeRawData* rootNodeData = reinterpret_cast <MetadataTreeNodeRawData*>(m_nodeData);
2231
@@ -43,21 +52,22 @@ MetadataTreeNode* MetadataReader::BuildTree() {
4352 node->children = new vector<MetadataTreeNode*>;
4453 MetadataTreeNodeRawData* childNodeData = rootNodeData + curNodeData->firstChildId ;
4554 while (true ) {
55+
56+ uint16_t childNodeDataId = childNodeData - rootNodeData;
57+ // node (and its next siblings) already visited, so we don't need to visit it again
58+ if (m_v[childNodeDataId] != emptyNode) {
59+ break ;
60+ }
61+
4662 MetadataTreeNode* childNode = new MetadataTreeNode;
4763 childNode->parent = node;
4864 childNode->name = ReadName (childNodeData->offsetName );
4965 childNode->offsetValue = childNodeData->offsetValue ;
5066
5167 node->children ->push_back (childNode);
5268
53- uint16_t childNodeDataId = childNodeData - rootNodeData;
54-
5569 m_v[childNodeDataId] = childNode;
5670
57- if (childNodeDataId == childNodeData->nextSiblingId ) {
58- break ;
59- }
60-
6171 childNodeData = rootNodeData + childNodeData->nextSiblingId ;
6272 }
6373 }
0 commit comments