Skip to content

Commit d5e746b

Browse files
authored
Refactor GetLocked and SetLocked to structs
1 parent 8b36073 commit d5e746b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

python/tensorstore/tensorstore_class.cc

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,12 +2889,6 @@ struct ArrayStorageStatisticsAccessor {
28892889
if (self.mask & MaskEntry) return self.*Member;
28902890
return {};
28912891
};
2892-
constexpr static inline auto GetLocked =
2893-
[](with_handle<const ArrayStorageStatistics&> self)
2894-
-> std::optional<bool> {
2895-
ScopedPyCriticalSection cs(self.handle.ptr());
2896-
return Get(self.value);
2897-
};
28982892

28992893
constexpr static inline auto Set = [](ArrayStorageStatistics& self,
29002894
std::optional<bool> value) {
@@ -2906,11 +2900,22 @@ struct ArrayStorageStatisticsAccessor {
29062900
self.*Member = {};
29072901
}
29082902
};
2909-
constexpr static inline auto SetLocked =
2910-
[](with_handle<ArrayStorageStatistics&> self, std::optional<bool> value) {
2911-
ScopedPyCriticalSection cs(self.handle.ptr());
2912-
return Set(self.value, std::move(value));
2913-
};
2903+
2904+
struct GetLocked {
2905+
std::optional<bool> operator()(
2906+
with_handle<const ArrayStorageStatistics&> self) const {
2907+
ScopedPyCriticalSection cs(self.handle.ptr());
2908+
return ArrayStorageStatisticsAccessor::Get(self.value);
2909+
}
2910+
};
2911+
2912+
struct SetLocked {
2913+
void operator()(with_handle<ArrayStorageStatistics&> self,
2914+
std::optional<bool> value) {
2915+
ScopedPyCriticalSection cs(self.handle.ptr());
2916+
return ArrayStorageStatisticsAccessor::Set(self.value, std::move(value));
2917+
}
2918+
};
29142919
};
29152920

29162921
void DefineArrayStorageStatisticsAttributes(ArrayStorageStatisticsCls& cls) {
@@ -2936,7 +2941,7 @@ Constructs from attribute values.
29362941
py::kw_only(), py::arg("not_stored") = std::nullopt,
29372942
py::arg("fully_stored") = std::nullopt);
29382943

2939-
cls.def_property("not_stored", NotStored::GetLocked, NotStored::SetLocked,
2944+
cls.def_property("not_stored", NotStored::GetLocked{}, NotStored::SetLocked{},
29402945
R"(
29412946
Indicates whether *no* data is stored for the specified :py:obj:`~TensorStore.domain`.
29422947
@@ -2948,8 +2953,8 @@ If :python:`False`, it is guaranteed that all elements within the domain are equ
29482953
to the :py:obj:`~TensorStore.fill_value`.
29492954
)");
29502955

2951-
cls.def_property("fully_stored", FullyStored::GetLocked,
2952-
FullyStored::SetLocked,
2956+
cls.def_property("fully_stored", FullyStored::GetLocked{},
2957+
FullyStored::SetLocked{},
29532958
R"(
29542959
Indicates whether data is stored for *all* elements of the specified :py:obj:`~TensorStore.domain`.
29552960

0 commit comments

Comments
 (0)