Fix increased build time and memory consumption caused by multiple ov::Any instantiation (#10452)
* Fix increased build time and memory consumption caused by multiple instansion of ov::Any. * delete unused method, correct exception message * codestyle * Resolve review comment * fix exception: throw it in else branch
This commit is contained in:
1 parent
926460e603
commit
3597ae61f9
3 files changed
+46
-15
No files matched your search
@@ -958,6 +958,18 @@ public:
|
||||
impl_check();
|
||||
return _impl.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns address to internal value if any is not empty and `nullptr` instead
|
||||
* @return address to internal stored value
|
||||
*/
|
||||
void* addressof();
|
||||
|
||||
/**
|
||||
* @brief Returns address to internal value if any is not empty and `nullptr` instead
|
||||
* @return address to internal stored value
|
||||
*/
|
||||
const void* addressof() const;
|
||||
};
|
||||
|
||||
/** @cond INTERNAL */
|
||||
|
||||
@@ -35,9 +35,6 @@ public:
|
||||
/// as_type.
|
||||
virtual const DiscreteTypeInfo& get_type_info() const = 0;
|
||||
virtual ~ValueAccessor() = default;
|
||||
virtual ov::Any get_as_any() {
|
||||
throw ov::Exception("get_as_any is not implemented");
|
||||
}
|
||||
virtual void set_as_any(const ov::Any& x) {
|
||||
throw ov::Exception("set_as_any is not implemented");
|
||||
}
|
||||
@@ -59,11 +56,14 @@ public:
|
||||
virtual const VAT& get() = 0;
|
||||
/// Sets the value
|
||||
virtual void set(const VAT& value) = 0;
|
||||
ov::Any get_as_any() override {
|
||||
return get();
|
||||
}
|
||||
void set_as_any(const ov::Any& x) override {
|
||||
set(x.as<VAT>());
|
||||
const auto* data = x.addressof();
|
||||
OPENVINO_ASSERT(data != nullptr, "Data conversion is not possible. Empty data is provided.");
|
||||
if (x.is<VAT>()) {
|
||||
set(*static_cast<const VAT*>(data));
|
||||
} else {
|
||||
OPENVINO_UNREACHABLE("Bad cast from: ", x.type_info().name(), " to: ", typeid(VAT).name());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,14 +108,18 @@ public:
|
||||
}
|
||||
|
||||
void set_as_any(const ov::Any& x) override {
|
||||
const auto* data = x.addressof();
|
||||
OPENVINO_ASSERT(data != nullptr, "Data conversion is not possible. Empty data is provided.");
|
||||
// Try to represent x as VAT or AT
|
||||
if (x.is<VAT>()) {
|
||||
set(x.as<VAT>());
|
||||
} else {
|
||||
set(*static_cast<const VAT*>(data));
|
||||
} else if (x.is<AT>()) {
|
||||
// Don't call set here avoiding unnecessary casts AT -> VAT -> AT,
|
||||
// instead reimplement logic from set.
|
||||
m_ref = x.as<AT>();
|
||||
m_ref = *static_cast<const AT*>(data);
|
||||
m_buffer_valid = false;
|
||||
} else {
|
||||
OPENVINO_UNREACHABLE("Bad cast from: ", x.type_info().name(), " to: ", typeid(AT).name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,14 +157,18 @@ public:
|
||||
}
|
||||
|
||||
void set_as_any(const ov::Any& x) override {
|
||||
const auto* data = x.addressof();
|
||||
OPENVINO_ASSERT(data != nullptr, "Data conversion is not possible. Empty data is provided.");
|
||||
// Try to represent x as VAT or AT
|
||||
if (x.is<VAT>()) {
|
||||
set(x.as<VAT>());
|
||||
} else {
|
||||
set(*static_cast<const VAT*>(data));
|
||||
} else if (x.is<AT>()) {
|
||||
// Don't call set here avoiding unnecessary casts AT -> VAT -> AT,
|
||||
// instead reimplement logic from set.
|
||||
m_ref = x.as<AT>();
|
||||
m_ref = *static_cast<const AT*>(data);
|
||||
m_buffer_valid = false;
|
||||
} else {
|
||||
OPENVINO_UNREACHABLE("Bad cast from: ", x.type_info().name(), " to: ", typeid(AT).name());
|
||||
}
|
||||
}
|
||||
operator AT&() {
|
||||
@@ -196,13 +204,17 @@ public:
|
||||
}
|
||||
|
||||
void set_as_any(const ov::Any& x) override {
|
||||
const auto* data = x.addressof();
|
||||
OPENVINO_ASSERT(data != nullptr, "Data conversion is not possible. Empty data is provided.");
|
||||
// Try to represent x as std::string or AT
|
||||
if (x.is<std::string>()) {
|
||||
set(x.as<std::string>());
|
||||
} else {
|
||||
} else if (x.is<AT>()) {
|
||||
// Don't call set here avoiding unnecessary casts AT -> std::string -> AT,
|
||||
// instead reimplement logic from set.
|
||||
m_ref = x.as<AT>();
|
||||
m_ref = *static_cast<const AT*>(data);
|
||||
} else {
|
||||
OPENVINO_UNREACHABLE("Bad cast from: ", x.type_info().name(), " to: ", typeid(AT).name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,13 @@ const Any::Base* Any::operator->() const {
|
||||
return _impl.get();
|
||||
}
|
||||
|
||||
void* Any::addressof() {
|
||||
return _impl != nullptr ? _impl->addressof() : nullptr;
|
||||
}
|
||||
|
||||
const void* Any::addressof() const {
|
||||
return _impl != nullptr ? _impl->addressof() : nullptr;
|
||||
}
|
||||
namespace util {
|
||||
|
||||
void Read<bool>::operator()(std::istream& is, bool& value) const {
|
||||
|
||||
Reference in new issue
Block a user