From 11e4188cc44cf9f1be996871919c7ddeac0ee818 Mon Sep 17 00:00:00 2001 From: qiuyu Date: Fri, 1 Jul 2022 17:39:42 +0800 Subject: [PATCH] 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 Change-Id: I0b6b863650137055cef4d28c44217b3c0bcbd417 --- assembler/annotation.cpp | 10 ++++++++++ assembler/annotation.h | 20 +------------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/assembler/annotation.cpp b/assembler/annotation.cpp index 1df84fd..0a47cf1 100644 --- a/assembler/annotation.cpp +++ b/assembler/annotation.cpp @@ -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(element); +} } // namespace panda::pandasm diff --git a/assembler/annotation.h b/assembler/annotation.h index 8e35d0e..8d45905 100644 --- a/assembler/annotation.h +++ b/assembler/annotation.h @@ -60,25 +60,7 @@ public: elements_.push_back(std::forward(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 eles; - for (size_t i = 0; i < ele_idx; i++) { - eles.push_back(std::forward(elements_[i])); - } - eles.push_back(std::forward(element)); - for (size_t i = ele_idx + 1; i < len; i++) { - eles.push_back(std::forward(elements_[i])); - } - elements_ = std::forward>(eles); - } + void SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element); private: std::string record_name_;