Page MenuHomeFeedback Tracker

A command to replace BIS_fnc_consolidateArray
New, NormalPublic

Description

BIS_fnc_consolidateArray is really, really slow, and could use a command to replace it. I managed to get a 3x speed increase by making a custom version of this function using HashMaps, but I believe that is still very much slower than an engine command could do.

Syntax examples:
consolidateArray ARRAY
consolidateArray ["apple","apple","pear","pear","apple"]; //Return: [["apple",3],["pear",2]]

This could (and probably should) be a HashMap as well:

_fruitMap = consolidateArray ["apple","apple","pear","pear","apple"];
_fruitMap get "apple" // Return: 3

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting
Additional Information

An example of how slow BIS_fnc_consolidateArray is:

_target = missionAmmoCrate; // This is a B_CargoNet_01_ammo_F straight from 3den

private _containerItems = [];
_containerItems append (weaponCargo _target);
_containerItems append (itemCargo _target);
_containerItems append (magazineCargo _target);
_containerItems append (backpackCargo _target);
_containerItems call BIS_fnc_consolidateArray

// Execution Time: 3.0684 ms  |  Cycles: 327/10000  |  Total Time: 1003 ms

Event Timeline

Yes, it's very fast. The problem is that uniqueUnitItems only works on units, so it's of no use in a lot of cases, such as the example I gave. The proposed command could be used on any array, which is why I feel like it'd be a good addition, and better than just adding a command specifically tailored to the example I gave, for example.

Maybe something that can be looked at