Skip to content

Cheaper string.Trim* functions for E2#3626

Merged
Astralcircle merged 3 commits into
masterfrom
Astralcircle-patch-1
Jun 14, 2026
Merged

Cheaper string.Trim* functions for E2#3626
Astralcircle merged 3 commits into
masterfrom
Astralcircle-patch-1

Conversation

@Astralcircle

Copy link
Copy Markdown
Contributor

I took some code from Starfall to make the regex check less strict

I took some code from Starfall to make the regex check less strict
@thegrb93

Copy link
Copy Markdown
Contributor

Didn't you have an even faster implementation with string.byte? These funcs don't have a pattern matching input so you could use the string.byte one.

@Astralcircle

Copy link
Copy Markdown
Contributor Author

Yes, but i only made them for string.Trim and string.TrimRight, so i decided to force all functions to use patterns for consistency, but i can probably just write a custom implementation for string.TrimLeft as well?

@thegrb93

Copy link
Copy Markdown
Contributor

TrimLeft and TrimRight are the same as Trim except they only search one side, so yeah it should be easy to just have two local functions that search the left/right and then just

function string.Trim(s) return string.sub(s, findLeftTrim(s), findRightTrim(s)) end
function string.TrimLeft(s) return string.sub(s, findLeftTrim(s)) end
function string.TrimRight(s) return string.sub(s, 1, findRightTrim(s)) end

@Astralcircle Astralcircle merged commit 75d5ac2 into master Jun 14, 2026
1 check failed
@Astralcircle Astralcircle deleted the Astralcircle-patch-1 branch June 14, 2026 04:16
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