Skip to content

Commit

Permalink
Remove useless runtime checks in span implementation (#1029)
Browse files Browse the repository at this point in the history
Both checks for Expects(ExtentType::size() != dynamic_extent); in storage_type are always useless. storage_type<ExtentType> is only ever created with ExtentType == extent_type<Extent>, where Extent has type std::size_t and is the extent of the span.

Looking at extent_type<std::size_t Ext>::size():

- if Ext != dynamic_extent, then size() always returns Ext, and therefore size() != dynamic_extent
- if Ext == dynamic_extent, then size() returns extent_type<dynamic_extent>::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<Other> ext) : size_(ext.size()), which simply relies on the other extent's size() method
So there is no way for ExtentType::size() == dynamic_extent.
  • Loading branch information
dmitrykobets-msft committed Apr 28, 2022
1 parent d8c493c commit da01eb2
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions include/gsl/span
Expand Up @@ -706,14 +706,11 @@ private:
template <class OtherExtentType>
constexpr storage_type(KnownNotNull data, OtherExtentType ext)
: ExtentType(ext), data_(data.p)
{
Expects(ExtentType::size() != dynamic_extent);
}
{}

template <class OtherExtentType>
constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data)
{
Expects(ExtentType::size() != dynamic_extent);
Expects(data || ExtentType::size() == 0);
}

Expand Down

0 comments on commit da01eb2

Please sign in to comment.