Strings - Cleanup + Optimize string functions - #1853
Open
LinkIsGrim wants to merge 7 commits into
Open
Conversation
Dystopian
reviewed
Aug 23, 2026
|
|
||
| // Detect if and how unicode support was forced | ||
| private _unicode = count "д" == 1; | ||
| private _forceUnicode = count "д" == 1; |
Contributor
There was a problem hiding this comment.
Suggested change
| private _forceUnicode = count "д" == 1; | |
| private _forceUnicode = count "д" == 1; // differs from _unicode if forceUnicode was 1 |
made me read the docs
PabstMirror
approved these changes
Aug 25, 2026
rautamiekka
suggested changes
Aug 25, 2026
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| if (_this == 0) then {"0"} else {str parseNumber (str (_this % _this) + str floor abs _this) + "." + (str (abs _this - floor abs _this) select [2]) + "0"}; | ||
| if (_this == 0) then {"0"} else {str parseNumber (str (_this % _this) + str floor abs _this) + "." + (str (abs _this - floor abs _this) select [2]) + "0"} |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_this == 0) then {"0"} else {str parseNumber (str (_this % _this) + str floor abs _this) + "." + (str (abs _this - floor abs _this) select [2]) + "0"} | |
| if (_this isEqualTo 0) then {"0"} else {str parseNumber (str (_this % _this) + str floor abs _this) + "." + (str (abs _this - floor abs _this) select [2]) + "0"} |
| private _result = ""; | ||
| private _offset = count (_find splitString ""); | ||
| // "1" find "" -> 0 | ||
| if (_find == "") exitWith {_string}; |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_find == "") exitWith {_string}; | |
| if (_find isEqualTo "") exitWith {_string}; |
| while {_string find _find != -1} do { | ||
| private _index = _string find _find; | ||
| // building the pattern costs more than this check, and most calls don't match | ||
| if (_string find _find == -1) exitWith {_string}; |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_string find _find == -1) exitWith {_string}; | |
| if (_string find _find isEqualTo -1) exitWith {_string}; |
| // starts an escape (\U, \L). Doubling both is what writes them out as themselves. | ||
| private _format = _replace; | ||
|
|
||
| if (_format find "\" != -1) then { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_format find "\" != -1) then { | |
| if (_format find "\" isNotEqualTo -1) then { |
Wouldn't even findIf be faster, even if uglier ? Dunno about in, but regexMatch tends to be faster last I tried.
| _format = _format regexReplace ["\\", "\\\\"]; | ||
| }; | ||
|
|
||
| if (_format find "$" != -1) then { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_format find "$" != -1) then { | |
| if (_format find "$" isNotEqualTo -1) then { |
|
|
||
| if (_find == 0) then { | ||
| _index = _index + _separatorCount; | ||
| if (_found == -1) exitWith { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_found == -1) exitWith { | |
| if (_found isEqualTo -1) exitWith { |
|
|
||
| _string = [_string, _trim] call CBA_fnc_rightTrim; | ||
| // Trim all whitespace characters by default | ||
| if (_trim == "") exitWith { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (_trim == "") exitWith { | |
| if (_trim isEqualTo "") exitWith { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When merged this pull request will:
All tests passing. Modified implementations (replace and split) are faster. 2.2x on split, replace speed improvements scale with length/matches. sanitizeHTML and decodeURL get faster due to using replace in implementation.
Probably add HEMTT lints for below eventually as they can be trivially replaced by engine commands?
CBA_fnc_strLencount _stringcount (_this select 0)CBA_fnc_trimtrim _string""CBA_fnc_trim_string trim [_chars, 0]CBA_fnc_leftTrim_string trim [_chars, 1]CBA_fnc_rightTrim_string trim [_chars, 2]CBA_fnc_find_haystack find [_needle, _index]CBA_fnc_substr_string select [_start]CBA_fnc_substr_string select [_start, _length]CBA_fnc_substring_string select [_start, _end + 1 - _start]selecttakes a lengthCBA_fnc_floatToStringtoFixed