mirror of
https://github.com/microsoft/GSL.git
synced 2025-01-18 09:44:59 -05:00
Remove useless runtime checks in span implementation (#1029)
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.
This commit is contained in:
parent
d8c493c89f
commit
da01eb28db
@ -706,14 +706,11 @@ private:
|
|||||||
template <class OtherExtentType>
|
template <class OtherExtentType>
|
||||||
constexpr storage_type(KnownNotNull data, OtherExtentType ext)
|
constexpr storage_type(KnownNotNull data, OtherExtentType ext)
|
||||||
: ExtentType(ext), data_(data.p)
|
: ExtentType(ext), data_(data.p)
|
||||||
{
|
{}
|
||||||
Expects(ExtentType::size() != dynamic_extent);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class OtherExtentType>
|
template <class OtherExtentType>
|
||||||
constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data)
|
constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data)
|
||||||
{
|
{
|
||||||
Expects(ExtentType::size() != dynamic_extent);
|
|
||||||
Expects(data || ExtentType::size() == 0);
|
Expects(data || ExtentType::size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user