Set indexes directly rather than incrementing step by step

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:01 +01:00
parent d59bbd1020
commit c048b187b4
2 changed files with 13 additions and 11 deletions
+12 -11
View File
@@ -356,14 +356,15 @@ bool YamlTreeWalker::toNextElmt()
if (isIdxInvalid()) {
setIdxInvalid(false);
stack[stack_level].elmts = 0;
setElmts(0);
}
if (getElmts() >= node->u._array.u._a.elmts - 1)
if (getElmts() < node->u._array.u._a.elmts - 1) {
incElmts();
rewind();
} else {
return false;
incElmts();
rewind();
}
}
return true;
@@ -455,16 +456,16 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
else
i = yaml_str2uint(buf, len);
//TODO: detect -1 and set idx_invalid = true
while ((i > getElmts()) && toNextElmt());
if (i > getElmts())
const YamlNode* node = getNode();
if (i < node->u._array.u._a.elmts) {
setElmts(i);
rewind();
} else {
setIdxInvalid(true);
}
}
else {
yaml_set_attr(data, getBitOffset(), attr, getParentElmts(), buf, len);
//walker.dump_stack();
}
}
@@ -73,6 +73,7 @@ class YamlTreeWalker
void incAttr() { stack[stack_level].attr_idx++; }
void incElmts() { stack[stack_level].elmts++; }
void setElmts(uint16_t idx) { stack[stack_level].elmts = idx; }
inline bool isIdxInvalid() {
return stack[stack_level].flags & FLAG_STATE_IDX_INVALID;