内存优化

This commit is contained in:
2026-08-28 11:49:05 +08:00
parent 42392bbb7e
commit 317c714e78
@@ -632,6 +632,13 @@ private:
});
}
template <class Function>
decltype(auto) with_all_readable_locked_impl(Function&& function) const {
using Schema = type_descriptor_schema_t<Derived>;
auto targets = collect_all_static_lock_targets<true>();
Static_Read_Guard<Schema::property_count> guard{*this, std::move(targets)};
return std::invoke(std::forward<Function>(function), guard);
}
template <class Function>
void with_all_writable_locked_impl(Function&& function) {
using Schema = type_descriptor_schema_t<Derived>;
auto targets = collect_all_static_lock_targets<false>();
@@ -777,6 +784,20 @@ public:
constexpr auto index = schema_member_property_index_v<Schema, Member>;
return read_one<index>();
}
template <std::size_t Index, class Function>
decltype(auto) with_read_index(Function&& function) const {
using Schema = type_descriptor_schema_t<Derived>;
static_assert(Index < Schema::property_count);
static_assert(Schema::template property_type<Index>::readable);
const auto lock_slot = slot(Index);
Single_Read_View<Index> view{*this, lock_slot};
if constexpr(!uses_real_mutexes)
return std::invoke(std::forward<Function>(function), read_unlocked<Index>(view));
if (lock_slot == Resolved_Synchronization_View::unsynchronized_slot)
return std::invoke(std::forward<Function>(function), read_unlocked<Index>(view));
std::shared_lock lock{mutex(lock_slot)};
return std::invoke(std::forward<Function>(function), read_unlocked<Index>(view));
}
template <Fixed_String Key>
auto read() const requires Schema_Readable_Property_Key<type_descriptor_schema_t<Derived>, Key> {
using Schema = type_descriptor_schema_t<Derived>;
@@ -864,6 +885,10 @@ public:
for_each_readable_locked_impl(std::forward<Function>(function));
}
template <class Function>
decltype(auto) with_all_readable_locked(Function&& function) const {
return with_all_readable_locked_impl(std::forward<Function>(function));
}
template <class Function>
void with_all_writable_locked(Function&& function) {
with_all_writable_locked_impl(std::forward<Function>(function));
}