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

hashSet - Use deleteAt to remove #445

Merged
merged 1 commit into from
Jul 27, 2016
Merged
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
13 changes: 3 additions & 10 deletions addons/hashes/fnc_hashSet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,13 @@ private _index = (_hash select HASH_KEYS) find _key;

if (_index >= 0) then {
if (_isDefault) then {
// Remove the key, if the new value is the default value.
// Do this by copying the key and value of the last element
// in the hash to the position of the element to be removed.
// Then, shrink the key and value arrays by one. (#2407)
// Remove the key and value, if the new value is the default value or nil

private _keys = _hash select HASH_KEYS;
private _values = _hash select HASH_VALUES;
private _last = (count _keys) - 1;

_keys set [_index, _keys select _last];
_keys resize _last;

_values set [_index, _values select _last];
_values resize _last;
_keys deleteAt _index;
_values deleteAt _index;
} else {
// Replace the original value for this key.
TRACE_2("VM CHECK SET",_index,_value);
Expand Down