Description
In pulsync-derive/src/lib.rs, extract_field_name checks for the "self." prefix by cloning the entire remaining character iterator and collecting it into a String on every { encountered:
// line 126 — allocates a new String of all remaining chars on every '{'
if chars.clone().collect::<String>().as_str().starts_with("self.") {
For a format string with K fields and average remaining length L, this is O(K × L) allocations — quadratic in the number of characters in the worst case.
Affected file
- pulsync-derive/src/lib.rs — line 126
Fix
std::str::Chars exposes the remaining string slice via .as_str(), which avoids any allocation:
// O(5), zero allocation
if chars.as_str().starts_with("self.") {
for _ in 0..5 { chars.next(); }
}
This is a one-line change that makes the method O(n) overall.
Description
In pulsync-derive/src/lib.rs, extract_field_name checks for the "self." prefix by cloning the entire remaining character iterator and collecting it into a String on every { encountered:
For a format string with K fields and average remaining length L, this is O(K × L) allocations — quadratic in the number of characters in the worst case.
Affected file
Fix
std::str::Chars exposes the remaining string slice via .as_str(), which avoids any allocation:
This is a one-line change that makes the method O(n) overall.