meta: avoid invoking .data() more than once
This commit is contained in:
1
TODO
1
TODO
@@ -14,7 +14,6 @@ TODO (high prio):
|
||||
* further optimize exclusion lists in multi type views (no existence check)
|
||||
* doc: bump entities
|
||||
* deprecate/drop snapshot orphans function, make it a general purpose one
|
||||
* avoid invoking ::data twice if possible ie within meta_associative_container::begin()
|
||||
|
||||
WIP:
|
||||
* get rid of observers, storage based views made them pointless - document alternatives
|
||||
|
||||
@@ -58,13 +58,14 @@ struct basic_meta_sequence_container_traits {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator iter(const meta_ctx &ctx, void *container, const void *as_const, const bool as_end) {
|
||||
if(auto *const cont = static_cast<Type *>(container); cont) {
|
||||
return iterator{ctx, as_end ? cont->end() : cont->begin()};
|
||||
[[nodiscard]] static iterator iter(const meta_ctx &ctx, const void *container, const bool as_const, const bool as_end) {
|
||||
if(as_const) {
|
||||
const auto it = as_end ? static_cast<const Type *>(container)->end() : static_cast<const Type *>(container)->begin();
|
||||
return iterator{ctx, it};
|
||||
} else {
|
||||
const auto it = as_end ? static_cast<Type *>(const_cast<void *>(container))->end() : static_cast<Type *>(const_cast<void *>(container))->begin();
|
||||
return iterator{ctx, it};
|
||||
}
|
||||
|
||||
auto *const cont = static_cast<const Type *>(as_const);
|
||||
return iterator{ctx, as_end ? cont->end() : cont->begin()};
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator insert_or_erase([[maybe_unused]] const meta_ctx &ctx, [[maybe_unused]] void *container, [[maybe_unused]] const any &handle, [[maybe_unused]] meta_any &value) {
|
||||
@@ -110,13 +111,14 @@ struct basic_meta_associative_container_traits {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator iter(const meta_ctx &ctx, void *container, const void *as_const, const bool as_end) {
|
||||
if(auto *const cont = static_cast<Type *>(container); cont) {
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, as_end ? cont->end() : cont->begin()};
|
||||
[[nodiscard]] static iterator iter(const meta_ctx &ctx, const void *container, const bool as_const, const bool as_end) {
|
||||
if(as_const) {
|
||||
const auto it = as_end ? static_cast<const Type *>(container)->end() : static_cast<const Type *>(container)->begin();
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, it};
|
||||
} else {
|
||||
const auto it = as_end ? static_cast<Type *>(const_cast<void *>(container))->end() : static_cast<Type *>(const_cast<void *>(container))->begin();
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, it};
|
||||
}
|
||||
|
||||
auto *const cont = static_cast<const Type *>(as_const);
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, as_end ? cont->end() : cont->begin()};
|
||||
}
|
||||
|
||||
[[nodiscard]] static size_type insert_or_erase(void *container, meta_any &key, meta_any &value) {
|
||||
@@ -135,13 +137,10 @@ struct basic_meta_associative_container_traits {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator find(const meta_ctx &ctx, void *container, const void *as_const, meta_any &key) {
|
||||
[[nodiscard]] static iterator find(const meta_ctx &ctx, const void *container, const bool as_const, meta_any &key) {
|
||||
if(key.allow_cast<const typename Type::key_type &>()) {
|
||||
if(auto *const cont = static_cast<Type *>(container); cont) {
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, cont->find(key.cast<const typename Type::key_type &>())};
|
||||
}
|
||||
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->find(key.cast<const typename Type::key_type &>())};
|
||||
return as_const ? iterator{ctx, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->find(key.cast<const typename Type::key_type &>())}
|
||||
: iterator{ctx, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->find(key.cast<const typename Type::key_type &>())};
|
||||
}
|
||||
|
||||
return iterator{};
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
internal::meta_type_node (*value_type_node)(const internal::meta_context &){};
|
||||
size_type (*size_fn)(const void *) noexcept {};
|
||||
bool (*resize_fn)(void *, size_type){};
|
||||
iterator (*iter_fn)(const meta_ctx &, void *, const void *, const bool){};
|
||||
iterator (*iter_fn)(const meta_ctx &, const void *, const bool, const bool){};
|
||||
iterator (*insert_or_erase_fn)(const meta_ctx &, void *, const any &, meta_any &){};
|
||||
any storage{};
|
||||
};
|
||||
@@ -143,9 +143,9 @@ private:
|
||||
internal::meta_type_node (*value_type_node)(const internal::meta_context &){};
|
||||
size_type (*size_fn)(const void *) noexcept {};
|
||||
bool (*clear_fn)(void *){};
|
||||
iterator (*iter_fn)(const meta_ctx &, void *, const void *, const bool){};
|
||||
iterator (*iter_fn)(const meta_ctx &, const void *, const bool, const bool){};
|
||||
size_type (*insert_or_erase_fn)(void *, meta_any &, meta_any &){};
|
||||
iterator (*find_fn)(const meta_ctx &, void *, const void *, meta_any &){};
|
||||
iterator (*find_fn)(const meta_ctx &, const void *, const bool, meta_any &){};
|
||||
any storage{};
|
||||
};
|
||||
|
||||
@@ -1867,7 +1867,7 @@ inline bool meta_sequence_container::clear() {
|
||||
* @return An iterator to the first element of the container.
|
||||
*/
|
||||
[[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::begin() {
|
||||
return iter_fn(*ctx, storage.data(), std::as_const(storage).data(), false);
|
||||
return iter_fn(*ctx, std::as_const(storage).data(), (storage.policy() == any_policy::cref), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1875,7 +1875,7 @@ inline bool meta_sequence_container::clear() {
|
||||
* @return An iterator that is past the last element of the container.
|
||||
*/
|
||||
[[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::end() {
|
||||
return iter_fn(*ctx, storage.data(), std::as_const(storage).data(), true);
|
||||
return iter_fn(*ctx, std::as_const(storage).data(), (storage.policy() == any_policy::cref), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1958,12 +1958,12 @@ inline bool meta_associative_container::clear() {
|
||||
|
||||
/*! @copydoc meta_sequence_container::begin */
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::begin() {
|
||||
return iter_fn(*ctx, storage.data(), std::as_const(storage).data(), false);
|
||||
return iter_fn(*ctx, std::as_const(storage).data(), (storage.policy() == any_policy::cref), false);
|
||||
}
|
||||
|
||||
/*! @copydoc meta_sequence_container::end */
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::end() {
|
||||
return iter_fn(*ctx, storage.data(), std::as_const(storage).data(), true);
|
||||
return iter_fn(*ctx, std::as_const(storage).data(), (storage.policy() == any_policy::cref), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2001,7 +2001,7 @@ inline meta_associative_container::size_type meta_associative_container::erase(m
|
||||
* @return An iterator to the element with the given key, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::find(meta_any key) {
|
||||
return find_fn(*ctx, storage.data(), std::as_const(storage).data(), key);
|
||||
return find_fn(*ctx, std::as_const(storage).data(), (storage.policy() == any_policy::cref), key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user