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

hashValues - don't copy arrays #1377

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion addons/hashes/fnc_hashValues.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ SCRIPT(hashValues);
// -----------------------------------------------------------------------------
params [["_hash", [[], []], [[]]]];

+(_hash select HASH_VALUES)
[] + (_hash select HASH_VALUES) // flat-copy
25 changes: 25 additions & 0 deletions addons/hashes/test_hashes.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TEST_DEFINED("CBA_fnc_hashHasKey","");
TEST_DEFINED("CBA_fnc_isHash","");
TEST_DEFINED("CBA_fnc_hashSize","");
TEST_DEFINED("CBA_fnc_hashKeys","");
TEST_DEFINED("CBA_fnc_hashValues","");

TEST_FALSE([[]] call CBA_fnc_isHash,"CBA_fnc_isHash");
_hash = [5, [4], [1], 2]; // Not a real hash.
Expand Down Expand Up @@ -128,4 +129,28 @@ TEST_OP(_keys,isEqualTo,[],"hashKeys");
_keys = [_hash] call CBA_fnc_hashKeys;
TEST_OP(_keys,isEqualTo,[ARR_3("123","124",125)],"hashKeys");

// Test CBA_fnc_hashValues
_hash = [] call CBA_fnc_hashCreate;
private _values = [_hash] call CBA_fnc_hashValues;
TEST_OP(_values,isEqualTo,[],"hashValues - empty");

[_hash, "a", 1] call CBA_fnc_hashSet;
[_hash, "b", 2] call CBA_fnc_hashSet;
_values = [_hash] call CBA_fnc_hashValues;
TEST_OP(_values,isEqualTo,[ARR_2(1,2)],"hashValues - values");

[_hash, "a"] call CBA_fnc_hashRem;
_values = [_hash] call CBA_fnc_hashValues;
TEST_OP(_values,isEqualTo,[2],"hashValues - removed");

_hash = [] call CBA_fnc_hashCreate;
private _data = [3];
[_hash, "c", _data] call CBA_fnc_hashSet;
_values = [_hash] call CBA_fnc_hashValues;
TEST_OP(_values,isEqualTo,[[3]],"hashValues - array");

_data pushBack [7];
TEST_OP(_values,isEqualTo,[[ARR_2(3,[7])]],"hashValues - deep array copy");


nil;