mirror of
https://github.com/openharmony/ark_runtime_core.git
synced 2026-07-01 13:17:23 -04:00
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:
@@ -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
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user