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

Replace all use of count as a forEach #1242

Merged
merged 3 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ GVAR(waitUntilAndExecArray) = [];
if (diag_tickTime > _delta) then {
_x set [2, _delta + _delay];
[_args, _handle] call _function;
false
};
} count GVAR(perFrameHandlerArray);
} forEach GVAR(perFrameHandlerArray);


// Execute wait and execute functions
Expand Down Expand Up @@ -64,8 +63,7 @@ GVAR(waitUntilAndExecArray) = [];
// Execute the exec next frame functions
{
(_x select 0) call (_x select 1);
false
} count GVAR(nextFrameBufferA);
} forEach GVAR(nextFrameBufferA);
// Swap double-buffer:
GVAR(nextFrameBufferA) = GVAR(nextFrameBufferB);
GVAR(nextFrameBufferB) = [];
Expand Down
9 changes: 3 additions & 6 deletions addons/jr/fnc_compatibleItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,17 @@ if (isNil "_compatibleItems") then {
if (isArray _cfgCompatibleItems) then {
{
_compatibleItems pushBackUnique _x;
nil
} count getArray _cfgCompatibleItems;
} forEach getArray _cfgCompatibleItems;
} else {
if (isClass _cfgCompatibleItems) then {
{
if (getNumber _x > 0) then {
_compatibleItems pushBackUnique configName _x;
};
nil
} count configProperties [_cfgCompatibleItems, "isNumber _x"];
} forEach configProperties [_cfgCompatibleItems, "isNumber _x"];
};
};
nil
} count configProperties [_cfgWeapon >> "WeaponSlotsInfo", "isclass _x"];
} forEach configProperties [_cfgWeapon >> "WeaponSlotsInfo", "isclass _x"];

GVAR(namespace) setVariable [_weapon, _compatibleItems]; //save entry in cache
} else {
Expand Down
5 changes: 2 additions & 3 deletions addons/statemachine/fnc_clockwork.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ SCRIPT(clockwork);
private _stateMachine = _x;
private _list = _stateMachine getVariable QGVAR(list);
private _skipNull = _stateMachine getVariable QGVAR(skipNull);
private _updateCode = _stateMachine getVariable QGVAR(updateCode);
private _id = _stateMachine getVariable QGVAR(ID);
private _tick = _stateMachine getVariable QGVAR(tick);

Expand All @@ -36,6 +35,7 @@ SCRIPT(clockwork);

// When the list was iterated through, jump back to start and update it
if (_tick >= count _list) then {
private _updateCode = _stateMachine getVariable QGVAR(updateCode);
commy2 marked this conversation as resolved.
Show resolved Hide resolved
_tick = 0;
if !(_updateCode isEqualTo {}) then {
_list = [] call _updateCode;
Expand Down Expand Up @@ -102,5 +102,4 @@ SCRIPT(clockwork);
(GVAR(performanceCounters) select _id) pushBack _perfRunTime;
#endif

false
} count GVAR(stateMachines);
} forEach GVAR(stateMachines);
9 changes: 3 additions & 6 deletions addons/statemachine/fnc_createFromConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ private _stateMachine = [_list, _skipNull] call FUNC(create);
GET_FUNCTION(_onStateLeaving,_x >> "onStateLeaving");
[_stateMachine, _onState, _onStateEntered, _onStateLeaving, _state] call FUNC(addState);

false
} count (configProperties [_config, "isClass _x", true]);
} forEach (configProperties [_config, "isClass _x", true]);

// We need to add the transitions in a second loop to make sure the states exist already
{
Expand All @@ -59,10 +58,8 @@ private _stateMachine = [_list, _skipNull] call FUNC(create);
[_stateMachine, _state, _targetState, _events, _condition, _onTransition, _transition] call FUNC(addEventTransition);
};

false
} count (configProperties [_x, "isClass _x", true]);
} forEach (configProperties [_x, "isClass _x", true]);

false
} count (configProperties [_config, "isClass _x", true]);
} forEach (configProperties [_config, "isClass _x", true]);

_stateMachine
3 changes: 1 addition & 2 deletions addons/xeh/fnc_addClassEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ _entities = _entities arrayIntersect _entities; // entities can return duplicate
};
};
};
true
} count _entities;
} forEach _entities;

// define for units that are created later
private _events = EVENTHANDLERS(_eventName,_className);
Expand Down
4 changes: 2 additions & 2 deletions addons/xeh/fnc_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ GVAR(EventsLowercase) = [];
FUNC(Init) = compileFinal (_header + "(_this select 0) call CBA_fnc_initEvents; (_this select 0) call CBA_fnc_init");
} else {
if (_x isEqualTo "HitPart") then {
FUNC(HitPart) = compileFinal (_header + format ['{call _x; nil} count ((_this select 0 select 0) getVariable QGVAR(%1))', _x]);
FUNC(HitPart) = compileFinal (_header + format ['{call _x} forEach ((_this select 0 select 0) getVariable QGVAR(%1))', _x]);
} else {
missionNamespace setVariable [
format [QFUNC(%1), _x],
compileFinal (_header + format ['{call _x; nil} count ((_this select 0) getVariable QGVAR(%1))', _x])
compileFinal (_header + format ['{call _x} forEach ((_this select 0) getVariable QGVAR(%1))', _x])
commy2 marked this conversation as resolved.
Show resolved Hide resolved
];
};
};
Expand Down
3 changes: 1 addition & 2 deletions addons/xeh/fnc_startFallbackLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ GVAR(fallbackRunning) = true;
{
// don't run init and initPost event handlers on objects that already exist
SETINITIALIZED(_x);
commy2 marked this conversation as resolved.
Show resolved Hide resolved
true
} count (entities [[], [], true, true]);
} count (entities [[], [], true, true]); // count is safe here because SETINITIALIZED is a setVariable, which returns nil

GVAR(entities) = [];

Expand Down