From da01eb28dbb75bed11a51acff0f80ecedd622573 Mon Sep 17 00:00:00 2001 From: dmitrykobets-msft <89153909+dmitrykobets-msft@users.noreply.github.com> Date: Thu, 28 Apr 2022 14:58:25 -0700 Subject: [PATCH] Remove useless runtime checks in span implementation (#1029) Both checks for Expects(ExtentType::size() != dynamic_extent); in storage_type are always useless. storage_type is only ever created with ExtentType == extent_type, where Extent has type std::size_t and is the extent of the span. Looking at extent_type::size(): - if Ext != dynamic_extent, then size() always returns Ext, and therefore size() != dynamic_extent - if Ext == dynamic_extent, then size() returns extent_type::size_. size_ can only be set via one of two constructors: - constexpr explicit extent_type(size_type size), which already does the check in question - constexpr explicit extent_type(extent_type ext) : size_(ext.size()), which simply relies on the other extent's size() method So there is no way for ExtentType::size() == dynamic_extent. --- include/gsl/span | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/gsl/span b/include/gsl/span index 4413a4d6..4d5bc7ce 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -706,14 +706,11 @@ private: template constexpr storage_type(KnownNotNull data, OtherExtentType ext) : ExtentType(ext), data_(data.p) - { - Expects(ExtentType::size() != dynamic_extent); - } + {} template constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data) { - Expects(ExtentType::size() != dynamic_extent); Expects(data || ExtentType::size() == 0); }