Use a simple way to implement SetOrAddElementByIndex

Move the implementation of SetOrAddElementByIndex from header to cpp file

Related Issue: https://gitee.com/openharmony/ark_runtime_core/issues/I5EDXX

Signed-off-by: qiuyu <qiuyu22@huawei.com>
Change-Id: I0b6b863650137055cef4d28c44217b3c0bcbd417
This commit is contained in:
qiuyu
2022-07-01 17:39:42 +08:00
parent e7fc0256b6
commit 11e4188cc4
2 changed files with 11 additions and 19 deletions
+10
View File
@@ -243,4 +243,14 @@ std::string AnnotationElement::TypeToString(Value::Type type)
}
}
void AnnotationData::SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element)
{
auto len = elements_.size();
ASSERT(ele_idx <= len);
if (ele_idx == len) {
AddElement(std::move(element));
return;
}
elements_[ele_idx] = std::forward<AnnotationElement>(element);
}
} // namespace panda::pandasm
+1 -19
View File
@@ -60,25 +60,7 @@ public:
elements_.push_back(std::forward<AnnotationElement>(element));
}
void SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element)
{
// did not find a simple way to replace element directly because of circular dependency of class definition
auto len = elements_.size();
ASSERT(ele_idx <= len);
if (ele_idx == len) {
AddElement(std::move(element));
return;
}
std::vector<AnnotationElement> eles;
for (size_t i = 0; i < ele_idx; i++) {
eles.push_back(std::forward<AnnotationElement>(elements_[i]));
}
eles.push_back(std::forward<AnnotationElement>(element));
for (size_t i = ele_idx + 1; i < len; i++) {
eles.push_back(std::forward<AnnotationElement>(elements_[i]));
}
elements_ = std::forward<std::vector<AnnotationElement>>(eles);
}
void SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element);
private:
std::string record_name_;