Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noexcept to all FontInfo structs #11640

Merged
3 commits merged into from
Oct 29, 2021
Merged

Add noexcept to all FontInfo structs #11640

3 commits merged into from
Oct 29, 2021

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Oct 28, 2021

FontInfoBase and it's descendents are missing noexcept annotations, which
virally forces other code to not be noexcept as well during AuditMode checks.
Apart from adding noexcept, this commit also

  • Passes std::wstring_view by reference.
  • Pass the FillLegacyNameBuffer argument as a simple pointer-to-array,
    allowing us to fill the buffer with a single memcpy.
    (gsl::span's iterators inhibit any internal STL optimizations.)
  • Move operator== declarations inside the class to reduce code size.

All other changes are an effect of the virality of noexcept.

This is an offshoot from #11623.

Validation Steps Performed

  • It still compiles ✔️

@lhecker lhecker added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. labels Oct 28, 2021
{
return _weight;
}

const std::wstring_view FontInfoBase::GetFaceName() const noexcept
const std::wstring& FontInfoBase::GetFaceName() const noexcept
Copy link
Member Author

@lhecker lhecker Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows you to call the technically more correct and safer .c_str() on the return value instead of hoping that the string_view refers to a null terminated string. (This could be changed in the UIA and GDI renderers. I'm making direct use of this safety in the AtlasEngine.)

return WasDefaultRasterSetFromEngine() || (GetFaceName().empty() &&
((_coordSizeDesired.X == 0 && _coordSizeDesired.Y == 0) ||
(_coordSizeDesired.X == 8 && _coordSizeDesired.Y == 12)));
return WasDefaultRasterSetFromEngine() || (GetFaceName().empty() && (_coordSizeDesired == COORD{ 0, 0 } || _coordSizeDesired == COORD{ 8, 12 }));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I thought to shorten the manual 4 X/Y comparisons into 2 struct comparisons.

const COORD coordSize,
const unsigned int codePage,
const bool fSetDefaultRasterFont /* = false */) :
FontInfo::FontInfo(const std::wstring_view& faceName, const unsigned char family, const unsigned int weight, const COORD coordSize, const unsigned int codePage, const bool fSetDefaultRasterFont) noexcept :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW The reason I scram these into a single line is because

  • (They still fit on most monitors and...)
  • Because it makes copy-pasting definitions into declarations and vice versa way easier IMHO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, I hate long single lines like this because I usually have two side-by-side panes, so 80-100 columns of width is preferable to me. Like, this line is 206 columns:
image

which is like 75% of the width of my monitor.

IDGAF, we'll just be in a constant struggle, you and I 😝

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it makes copy-pasting definitions into declarations and vice versa way easier IMHO

I usually use the "create definition / declaration" feature in VS ;P

Copy link
Member Author

@lhecker lhecker Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something like: If each definition is one line long you can use Ctrl-Alt-Up/Down to insert multiple cursors at the start of each line and for instance quickly add additional annotations at the end of each line. However if declarations are multiple lines long you need to hope the functions don’t use SAL or function pointers (for instance). (This is really just one example.)
I‘ll just revert this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am 100% okay with keeping this line long, FYI

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zadjii-msft If you want to you can re-review the latest 2 commits, which make this PR a bit more compact - both horizontally and diff-wise. 😅

@lhecker lhecker force-pushed the dev/lhecker/font-info-noexcept branch from d4d8e47 to 0af3d3a Compare October 28, 2021 13:51
@lhecker lhecker force-pushed the dev/lhecker/font-info-noexcept branch from 0af3d3a to f6b3d04 Compare October 28, 2021 14:43
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -77,21 +60,15 @@ unsigned int FontInfoBase::GetCodePage() const
// Arguments:
// - buffer: the buffer into which to copy characters
// - size: the size of buffer
HRESULT FontInfoBase::FillLegacyNameBuffer(gsl::span<wchar_t> buffer) const
try
void FontInfoBase::FillLegacyNameBuffer(wchar_t (&buffer)[LF_FACESIZE]) const noexcept
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wchar_t (&buffer)[LF_FACESIZE]

huh, never seen that notation before

const COORD coordSize,
const unsigned int codePage,
const bool fSetDefaultRasterFont /* = false */) :
FontInfo::FontInfo(const std::wstring_view& faceName, const unsigned char family, const unsigned int weight, const COORD coordSize, const unsigned int codePage, const bool fSetDefaultRasterFont) noexcept :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, I hate long single lines like this because I usually have two side-by-side panes, so 80-100 columns of width is preferable to me. Like, this line is 206 columns:
image

which is like 75% of the width of my monitor.

IDGAF, we'll just be in a constant struggle, you and I 😝

@DHowett
Copy link
Member

DHowett commented Oct 28, 2021

Surprised this compiled locally!

@lhecker
Copy link
Member Author

lhecker commented Oct 28, 2021

I only compiled Host.EXE. I didn’t consider the possibility that the FontInfo objects are used in WT classes without being used in OpenConsole. I‘ll fix the issues soon.

@lhecker lhecker force-pushed the dev/lhecker/font-info-noexcept branch from 124aa70 to 3187767 Compare October 29, 2021 12:11
@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 29, 2021
@ghost
Copy link

ghost commented Oct 29, 2021

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 95cc7d9 into main Oct 29, 2021
@ghost ghost deleted the dev/lhecker/font-info-noexcept branch October 29, 2021 14:08
@ghost
Copy link

ghost commented Feb 3, 2022

🎉Windows Terminal Preview v1.13.10336.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants