Skip to content

Add form-feed and vertical tab to trim defaults#2407

Merged
lerno merged 8 commits into
c3lang:masterfrom
NotsoanoNimus:update-trim-defaults
Aug 25, 2025
Merged

Add form-feed and vertical tab to trim defaults#2407
lerno merged 8 commits into
c3lang:masterfrom
NotsoanoNimus:update-trim-defaults

Conversation

@NotsoanoNimus
Copy link
Copy Markdown
Contributor

Add a few extra characters to the collection of default whitespace values in String trim methods.

See: C++'s std::isspace and C's isspace.

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented Aug 16, 2025

I know it's tradition, but no one uses those.

@NotsoanoNimus
Copy link
Copy Markdown
Contributor Author

I know it's tradition, but no one uses those.

But what if someone did? 😏

jokes aside, it would be good to grab as much actual ASCII whitespace as possible with the default value, right?

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented Aug 20, 2025

No, because it makes the filtering slower in this implementation. It's O(n) based on length.

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented Aug 21, 2025

Not that it will matter that much. If we used character sets directly it would be faster. I can make a fast trim that outperforms the current one by a factor 3.

@NotsoanoNimus
Copy link
Copy Markdown
Contributor Author

Alright, I'm now finished amending this pull request.

I added/fixed the benchmark (as well as the bench runtime). It now lines up with what you posted in Discord, per our discussion there.

Main takeaway: AsciiCharset is the clear victor for trimming regardless of the set size, but the charset trimming gets exponentially faster the larger the filter set is.

----------------------------- BENCHMARKS ------------------------------
Benchmarking string_trim_wars::trim_control ...................... [COMPLETE] 59.32 nanoseconds, 120.02 CPU clocks, 16777216 iterations (runtime 995.15 milliseconds)
Benchmarking string_trim_wars::trim_whitespace_default ........... [COMPLETE] 101.85 nanoseconds, 205.36 CPU clocks, 16777216 iterations (runtime 1.71 seconds)
Benchmarking string_trim_wars::trim_whitespace_default_ordered ... [COMPLETE] 80.39 nanoseconds, 161.45 CPU clocks, 16777216 iterations (runtime 1.35 seconds)
Benchmarking string_trim_wars::trim_whitespace_bad ............... [COMPLETE] 128.67 nanoseconds, 259.01 CPU clocks, 16777216 iterations (runtime 2.16 seconds)
Benchmarking string_trim_wars::trim_whitespace_ordered_extended .. [COMPLETE] 117.15 nanoseconds, 235.81 CPU clocks, 16777216 iterations (runtime 1.97 seconds)
Benchmarking string_trim_wars::trim_charset_whitespace ........... [COMPLETE] 94.11 nanoseconds, 189.68 CPU clocks, 16777216 iterations (runtime 1.58 seconds)
Benchmarking string_trim_wars::trim_many ......................... [COMPLETE] 242.63 nanoseconds, 486.38 CPU clocks, 16777216 iterations (runtime 4.07 seconds)
Benchmarking string_trim_wars::trim_charset_many ................. [COMPLETE] 168.14 nanoseconds, 338.05 CPU clocks, 16777216 iterations (runtime 2.82 seconds)

@lerno lerno merged commit 35c04cd into c3lang:master Aug 25, 2025
44 checks passed
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