C26497, use constexpr for functions that could be evaluated at compile time.

This commit is contained in:
Michael Niksa 2019-09-03 10:30:06 -07:00
parent b180406b07
commit c956913a28
8 changed files with 10 additions and 15 deletions

View file

@ -544,7 +544,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
// Return Value:
// - An estimate of how many glyph spaces may be required in the shaping arrays
// to hold the data from a string of the given length.
[[nodiscard]] UINT32 CustomTextLayout::_EstimateGlyphCount(const UINT32 textLength) noexcept
[[nodiscard]] constexpr UINT32 CustomTextLayout::_EstimateGlyphCount(const UINT32 textLength) noexcept
{
// This formula is from https://docs.microsoft.com/en-us/windows/desktop/api/dwrite/nf-dwrite-idwritetextanalyzer-getglyphs
// and is the recommended formula for estimating buffer size for glyph count.

View file

@ -132,7 +132,7 @@ namespace Microsoft::Console::Render
IDWriteTextRenderer* renderer,
const D2D_POINT_2F origin) noexcept;
[[nodiscard]] static UINT32 _EstimateGlyphCount(const UINT32 textLength) noexcept;
[[nodiscard]] static constexpr UINT32 _EstimateGlyphCount(const UINT32 textLength) noexcept;
private:
const ::Microsoft::WRL::ComPtr<IDWriteFactory1> _factory;

View file

@ -1797,12 +1797,7 @@ float DxEngine::GetScaling() const noexcept
// - color - Direct2D Color F
// Return Value:
// - DXGI RGBA
[[nodiscard]] DXGI_RGBA DxEngine::s_RgbaFromColorF(const D2D1_COLOR_F color) noexcept
[[nodiscard]] constexpr DXGI_RGBA DxEngine::s_RgbaFromColorF(const D2D1_COLOR_F color) noexcept
{
DXGI_RGBA rgba;
rgba.a = color.a;
rgba.b = color.b;
rgba.g = color.g;
rgba.r = color.r;
return rgba;
return { color.r, color.g, color.b, color.a };
}

View file

@ -209,6 +209,6 @@ namespace Microsoft::Console::Render
[[nodiscard]] D2D1_COLOR_F _ColorFFromColorRef(const COLORREF color) noexcept;
[[nodiscard]] static DXGI_RGBA s_RgbaFromColorF(const D2D1_COLOR_F color) noexcept;
[[nodiscard]] static constexpr DXGI_RGBA s_RgbaFromColorF(const D2D1_COLOR_F color) noexcept;
};
}

View file

@ -1098,8 +1098,8 @@ const ViewportRow UiaTextRangeBase::_screenInfoRowToViewportRow(IUiaData* pData,
// - viewport - the viewport to use for the conversion
// Return Value:
// - the equivalent ViewportRow.
const ViewportRow UiaTextRangeBase::_screenInfoRowToViewportRow(const ScreenInfoRow row,
const SMALL_RECT viewport) noexcept
constexpr const ViewportRow UiaTextRangeBase::_screenInfoRowToViewportRow(const ScreenInfoRow row,
const SMALL_RECT viewport) noexcept
{
return row - viewport.Top;
}

View file

@ -299,7 +299,7 @@ namespace Microsoft::Console::Types
static const ViewportRow _screenInfoRowToViewportRow(IUiaData* pData,
const ScreenInfoRow row);
static const ViewportRow _screenInfoRowToViewportRow(const ScreenInfoRow row,
static constexpr const ViewportRow _screenInfoRowToViewportRow(const ScreenInfoRow row,
const SMALL_RECT viewport) noexcept;
static const bool _isScreenInfoRowInViewport(IUiaData* pData,

View file

@ -15,7 +15,7 @@ namespace Microsoft::Console::Utils
{
bool IsValidHandle(const HANDLE handle) noexcept;
short ClampToShortMax(const long value, const short min) noexcept;
constexpr short ClampToShortMax(const long value, const short min) noexcept;
std::wstring GuidToString(const GUID guid);
GUID GuidFromString(const std::wstring wstr);

View file

@ -13,7 +13,7 @@ using namespace Microsoft::Console;
// - min: the minimum value to clamp to
// Return Value:
// - The clamped value as a short.
short Utils::ClampToShortMax(const long value, const short min) noexcept
constexpr short Utils::ClampToShortMax(const long value, const short min) noexcept
{
return static_cast<short>(std::clamp(value,
static_cast<long>(min),