From 3d5a6d38e65ad9e214901da901310a05f7a37a29 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 14 Apr 2021 18:50:50 +0200 Subject: [PATCH] Avoid calling size() in empty() member functions Might slightly improve the speed of applications built in Debug mode. Having `empty()` call `size()` is somewhat disappointing for users who follow the guideline to replace their `size()` calls by the corresponding `empty()` calls. For example by Clang-Tidy: https://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html --- stl/inc/vector | 2 +- stl/inc/xstring | 2 +- stl/inc/xtree | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/vector b/stl/inc/vector index 9a943420d43..52fef59fc25 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -2798,7 +2798,7 @@ public: } _NODISCARD _CONSTEXPR20_CONTAINER bool empty() const noexcept { - return size() == 0; + return this->_Mysize == 0; } _NODISCARD _CONSTEXPR20_CONTAINER allocator_type get_allocator() const noexcept { diff --git a/stl/inc/xstring b/stl/inc/xstring index 9e63cab02b2..36cef22456a 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4016,7 +4016,7 @@ public: #endif // _HAS_CXX20 _NODISCARD _CONSTEXPR20_CONTAINER bool empty() const noexcept { - return size() == 0; + return _Mypair._Myval2._Mysize == 0; } _CONSTEXPR20_CONTAINER size_type copy( diff --git a/stl/inc/xtree b/stl/inc/xtree index 3d9e6786ee0..12b8d6c7e79 100644 --- a/stl/inc/xtree +++ b/stl/inc/xtree @@ -1216,7 +1216,7 @@ public: } _NODISCARD bool empty() const noexcept { - return size() == 0; + return _Get_scary()->_Mysize == 0; } _NODISCARD allocator_type get_allocator() const noexcept {