Skip to content

Remove dependency of variant.h in print_string.h #107721

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YYF233333
Copy link
Contributor

print_string.h isn’t the lightweight header its name suggests—concerned only with String—but a fairly heavy one, because it includes variant.h internally. The only place it actually needs Variant is in stringfy_variants(). I changed that function to a non-template version and moved it into print_string.cpp, so now print_string.h only depends on ustring.h.

std::initializer_list may incur some overhead, but these functions don't seem to be particularly performance-sensitive, so I opted for the most straightforward implementation.

@YYF233333 YYF233333 requested review from a team as code owners June 19, 2025 16:06
Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

This is definitely worth doing.

But instead of std::initializer_list, it should use Span, I think. initializer_list is more meant for actual initialization, so it feels out-of-domain here.

You should also be able to simplify to just one templated function, by using something like this:

Variant variants[sizeof...(args)] = { args... };
__print_line(stringify_variants(Span(variants))

@YYF233333
Copy link
Contributor Author

But instead of std::initializer_list, it should use Span, I think. initializer_list is more meant for actual initialization, so it feels out-of-domain here.

You should also be able to simplify to just one templated function, by using something like this:

Changed and simplified. There is one more copy for one argument situation, but the overhead should be negiligible (actually I think compiler can optimize this away).

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

Works for me.

Co-authored-by: Lukas Tenbrink <[email protected]>
Co-authored-by: A Thousand Ships <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants