Skip to content

Use perfect forwarding in String::format#2853

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

Use perfect forwarding in String::format#2853
herwinw wants to merge 1 commit into
natalie-lang:masterfrom
herwinw:tm_string_format_forwarding

Conversation

@herwinw
Copy link
Copy Markdown
Member

@herwinw herwinw commented Dec 17, 2025

This means any rvalue references are now moved into the recursive call, instead of being copied.

The following example script:

TM::String foo() { return "foo"; }
TM::String bar() { return "bar"; }

int main() {
    TM::String::format("1={}, 2={}", foo(), bar()).print();
    return 0;
}

Showed about 1k operations in valgrind less with this patch (on a total of 1.9M operations, so don't expect miracles).

@herwinw herwinw force-pushed the tm_string_format_forwarding branch 2 times, most recently from 7a570a9 to e755a20 Compare December 19, 2025 12:53
@herwinw herwinw self-assigned this Dec 19, 2025
This means any rvalue references are now moved into the recursive call,
instead of being copied.

The following example script:
```c++

TM::String foo() { return "foo"; }
TM::String bar() { return "bar"; }

int main() {
    TM::String::format("1={}, 2={}", foo(), bar()).print();
    return 0;
}
```
Showed about 1k operations in valgrind less with this patch (on a total
of 1.9M operations, so don't expect miracles).
@herwinw herwinw force-pushed the tm_string_format_forwarding branch from e755a20 to 33806a0 Compare December 19, 2025 18:33
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.

2 participants