Skip to content

[NFC][libc++][TZDB] Improves some internals. #84800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions libcxx/include/__chrono/tzdb_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,29 @@ class _LIBCPP_AVAILABILITY_TZDB tzdb_list {

using const_iterator = forward_list<tzdb>::const_iterator;

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const tzdb& front() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); }

_LIBCPP_EXPORTED_FROM_ABI const_iterator erase_after(const_iterator __p);
_LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); }

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator begin() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator end() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); }
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); }

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cbegin() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cend() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); }
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); }

[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; }

private:
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& __front() const noexcept;

_LIBCPP_EXPORTED_FROM_ABI const_iterator __erase_after(const_iterator __p);

[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __begin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __end() const noexcept;

[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cbegin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cend() const noexcept;

__impl* __impl_;
};

Expand Down
11 changes: 4 additions & 7 deletions libcxx/src/include/tzdb/tzdb_list_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class tzdb_list::__impl {

using const_iterator = tzdb_list::const_iterator;

const tzdb& front() const noexcept {
const tzdb& __front() const noexcept {
#ifndef _LIBCPP_HAS_NO_THREADS
shared_lock __lock{__mutex_};
#endif
return __tzdb_.front();
}

const_iterator erase_after(const_iterator __p) {
const_iterator __erase_after(const_iterator __p) {
#ifndef _LIBCPP_HAS_NO_THREADS
unique_lock __lock{__mutex_};
#endif
Expand All @@ -70,20 +70,17 @@ class tzdb_list::__impl {
return __tzdb_.erase_after(__p);
}

const_iterator begin() const noexcept {
const_iterator __begin() const noexcept {
#ifndef _LIBCPP_HAS_NO_THREADS
shared_lock __lock{__mutex_};
#endif
return __tzdb_.begin();
}
const_iterator end() const noexcept {
const_iterator __end() const noexcept {
// forward_list<T>::end does not access the list, so no need to take a lock.
return __tzdb_.end();
}

const_iterator cbegin() const noexcept { return begin(); }
const_iterator cend() const noexcept { return end(); }

private:
// Loads the tzdbs
// pre: The caller ensures the locking, if needed, is done.
Expand Down
24 changes: 11 additions & 13 deletions libcxx/src/tzdb_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ namespace chrono {

_LIBCPP_EXPORTED_FROM_ABI tzdb_list::~tzdb_list() { delete __impl_; }

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const tzdb& tzdb_list::front() const noexcept {
return __impl_->front();
}
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& tzdb_list::__front() const noexcept { return __impl_->__front(); }

_LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::erase_after(const_iterator __p) {
return __impl_->erase_after(__p);
_LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::__erase_after(const_iterator __p) {
return __impl_->__erase_after(__p);
}

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::begin() const noexcept {
return __impl_->begin();
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::__begin() const noexcept {
return __impl_->__begin();
}
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::end() const noexcept {
return __impl_->end();
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::__end() const noexcept {
return __impl_->__end();
}

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::cbegin() const noexcept {
return __impl_->cbegin();
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::__cbegin() const noexcept {
return __impl_->__begin();
}
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::cend() const noexcept {
return __impl_->cend();
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::__cend() const noexcept {
return __impl_->__end();
}

} // namespace chrono
Expand Down