Set indexes directly rather than incrementing step by step
This commit is contained in:
@@ -356,14 +356,15 @@ bool YamlTreeWalker::toNextElmt()
|
|||||||
|
|
||||||
if (isIdxInvalid()) {
|
if (isIdxInvalid()) {
|
||||||
setIdxInvalid(false);
|
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;
|
return false;
|
||||||
|
}
|
||||||
incElmts();
|
|
||||||
rewind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -455,16 +456,16 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
|
|||||||
else
|
else
|
||||||
i = yaml_str2uint(buf, len);
|
i = yaml_str2uint(buf, len);
|
||||||
|
|
||||||
//TODO: detect -1 and set idx_invalid = true
|
const YamlNode* node = getNode();
|
||||||
|
if (i < node->u._array.u._a.elmts) {
|
||||||
while ((i > getElmts()) && toNextElmt());
|
setElmts(i);
|
||||||
|
rewind();
|
||||||
if (i > getElmts())
|
} else {
|
||||||
setIdxInvalid(true);
|
setIdxInvalid(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
yaml_set_attr(data, getBitOffset(), attr, getParentElmts(), buf, len);
|
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 incAttr() { stack[stack_level].attr_idx++; }
|
||||||
void incElmts() { stack[stack_level].elmts++; }
|
void incElmts() { stack[stack_level].elmts++; }
|
||||||
|
void setElmts(uint16_t idx) { stack[stack_level].elmts = idx; }
|
||||||
|
|
||||||
inline bool isIdxInvalid() {
|
inline bool isIdxInvalid() {
|
||||||
return stack[stack_level].flags & FLAG_STATE_IDX_INVALID;
|
return stack[stack_level].flags & FLAG_STATE_IDX_INVALID;
|
||||||
|
|||||||
Reference in New Issue
Block a user