Skip to content

Use perfect forwarding for StringObject::create#2772

Open
herwinw wants to merge 1 commit into
natalie-lang:masterfrom
herwinw:string_create_perfect_forwarding
Open

Use perfect forwarding for StringObject::create#2772
herwinw wants to merge 1 commit into
natalie-lang:masterfrom
herwinw:string_create_perfect_forwarding

Conversation

@herwinw
Copy link
Copy Markdown
Member

@herwinw herwinw commented Jul 3, 2025

This removes all the specialized implementations of StringObject::create with a generic one that just forwards the arguments to the actual private constructors. We can do the same thing with all other classes that have these create factory methods.

Small caveat: perfect forwarding is not perfect. The callers that use a stack allocated array don't work, these have been converted into calls using TM::String::create_and_take_ownership which removes a memcpy too.

@herwinw herwinw force-pushed the string_create_perfect_forwarding branch from 6ad888e to 7f5e85f Compare July 3, 2025 17:36
Copy link
Copy Markdown
Member

@seven1m seven1m left a comment

Choose a reason for hiding this comment

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

Well ain't that fancy!

Does the template programming slow down compilation at all? I do worry that using template programming seems to be slower (at compile time), at least with gcc.

@herwinw herwinw force-pushed the string_create_perfect_forwarding branch 2 times, most recently from 5797d6c to 35e09dd Compare July 6, 2025 09:28
@herwinw herwinw force-pushed the string_create_perfect_forwarding branch from 35e09dd to 3a8f4a3 Compare July 13, 2025 12:20
This removes the need for all the duplication of the constructors.
@herwinw herwinw force-pushed the string_create_perfect_forwarding branch from 3a8f4a3 to 06f1dec Compare July 13, 2025 13:44
@rolandpj1968
Copy link
Copy Markdown
Contributor

rolandpj1968 commented Dec 28, 2025

Well ain't that fancy!

Does the template programming slow down compilation at all? I do worry that using template programming seems to be slower (at compile time), at least with gcc.

This is an interesting question when running at -O3. Legend has it that -O2 is a better balance of compilation time vs perf.

But no inlining? Dunno what clang and gcc actually do nowadays.

I'm actually surprised that member fields can be forward-referenced in header files. My C++ foo is a bit rusty.

In any case we could definitely factor some of the instruction->c++ generation in order to cut parsing at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants