@@ -17,6 +17,15 @@ MetadataReader::MetadataReader(uint32_t nodesLength, uint8_t* nodeData, uint32_t
17
17
m_root = BuildTree ();
18
18
}
19
19
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
+
20
29
MetadataTreeNode* MetadataReader::BuildTree () {
21
30
MetadataTreeNodeRawData* rootNodeData = reinterpret_cast <MetadataTreeNodeRawData*>(m_nodeData);
22
31
@@ -43,21 +52,22 @@ MetadataTreeNode* MetadataReader::BuildTree() {
43
52
node->children = new vector<MetadataTreeNode*>;
44
53
MetadataTreeNodeRawData* childNodeData = rootNodeData + curNodeData->firstChildId ;
45
54
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
+
46
62
MetadataTreeNode* childNode = new MetadataTreeNode;
47
63
childNode->parent = node;
48
64
childNode->name = ReadName (childNodeData->offsetName );
49
65
childNode->offsetValue = childNodeData->offsetValue ;
50
66
51
67
node->children ->push_back (childNode);
52
68
53
- uint16_t childNodeDataId = childNodeData - rootNodeData;
54
-
55
69
m_v[childNodeDataId] = childNode;
56
70
57
- if (childNodeDataId == childNodeData->nextSiblingId ) {
58
- break ;
59
- }
60
-
61
71
childNodeData = rootNodeData + childNodeData->nextSiblingId ;
62
72
}
63
73
}
0 commit comments