From c048b187b48203f31cc1dc256585bfde178aa6e3 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 15 Oct 2021 15:33:55 +0200 Subject: [PATCH] Set indexes directly rather than incrementing step by step --- radio/src/storage/yaml/yaml_tree_walker.cpp | 23 +++++++++++---------- radio/src/storage/yaml/yaml_tree_walker.h | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/radio/src/storage/yaml/yaml_tree_walker.cpp b/radio/src/storage/yaml/yaml_tree_walker.cpp index 9f27dc32c..f9f2914dd 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.cpp +++ b/radio/src/storage/yaml/yaml_tree_walker.cpp @@ -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(); } } diff --git a/radio/src/storage/yaml/yaml_tree_walker.h b/radio/src/storage/yaml/yaml_tree_walker.h index c8e1f5591..c27da5c91 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.h +++ b/radio/src/storage/yaml/yaml_tree_walker.h @@ -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;