Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions - Replace ace_parse_imagepath with SQF regexFind #8243

Merged
merged 1 commit into from
Oct 10, 2021

Conversation

PabstMirror
Copy link
Contributor

slower than the extension, but a lot simpler

@PabstMirror PabstMirror added kind/cleanup Release Notes: **CHANGED:** target/next-arma Requires something in arma dev branch labels May 6, 2021
@jonpas
Copy link
Member

jonpas commented May 6, 2021

How much slower? Does it matter in this use case since it's interact menu?

@PabstMirror
Copy link
Contributor Author

1.31926 ms for 10x - Original SQF (Can sorta understand why I thought we needed an extension)
"<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />" call originalSqfFrom2015;

0.0094 ms for 10x - callExtension
"ace_parse_imagepath" callExtension "<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />";

0.0532 ms for 10x - new regex
(("<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />" regexFind ["[\w\-\\]+.paa",0]) param [0, [""]]) select 0;

0.0565 ms for 10x - "modern" SQF
"<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />" call modernSQF;

originalSqfFrom2015 = {
    params ["_actionDisplayNameDefault"];
    _iconImage = ""; 
    _endIndex = _actionDisplayNameDefault find ".paa'"; 
    if (_endIndex == -1) exitWith { "" }; 
    _startIndex = _endIndex - 1; 
    _endIndex = _endIndex + 4; 
    while {(_startIndex > 0) && {_iconImage == ""}} do { 
        if ((_actionDisplayNameDefault select [_startIndex, 1]) == "'") then { 
            _startIndex = _startIndex + 1; 
            _iconImage = _actionDisplayNameDefault select [_startIndex, (_endIndex - _startIndex)]; 
        }; 
        _startIndex = _startIndex - 1; 
    }; 
    _iconImage
};

yuck, no wonder it was so slow

better sqf would also be fine, something like

{
    params ["_input"]; 
    private _end = _input find ".paa'"; 
    if (_end == -1) exitWith { "" }; 
    private _startSub = reverse (_input select [0, _end]); 
    private _start = _end - (_startSub find "'"); 
    _input select [_start, (_end - _start + 4)]
}

@jonpas
Copy link
Member

jonpas commented May 9, 2021

Awesome! Always nice to see optimizations with some numbers!

@dedmen
Copy link
Contributor

dedmen commented May 18, 2021

Btw Arma 2.06 has regex.

@jonpas
Copy link
Member

jonpas commented Jul 23, 2021

Never mind, I forgot we are on 2.04 and not 2.06 yet. 🤕

@PabstMirror PabstMirror added this to the 3.14.0 milestone Oct 6, 2021
@PabstMirror PabstMirror removed the target/next-arma Requires something in arma dev branch label Oct 6, 2021
@jonpas jonpas changed the title Drop ace_parse_imagepath extension Extensions - Replace ace_parse_imagepath with SQF regexFind Oct 10, 2021
@jonpas jonpas merged commit 94c62d8 into master Oct 10, 2021
@jonpas jonpas deleted the regexRepaceExt branch October 10, 2021 13:41
AndreasBrostrom pushed a commit to AndreasBrostrom/ACE3 that referenced this pull request Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Release Notes: **CHANGED:**
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants