In solidity if you need to add an item to a mapping, i believe thats then called adding it to storage, from a function, is it better to make a memory variable of the struct and then pass that to the mapping. Or can you just better directly pass the struct to the mapping? it saves me an extremely little amount of gas to just write directly to add the struct directly to the mapping.
Here is an example of what i mean:
Counters.Counter private _ids;
Struct x = {
uint256 id;
uint256 value;
}
mapping(uint256 => x) private _xs;
function xCreate(uint256 _price) external {
_ids.increment();
uint256 itemId = _ids.current();
//Do it this way(1) ->
X memory x = X(
itemId,
_price
);
_xs[itemId] = x;
///////////////////
//Or do it this way(2) ->
_xs[itemId] = X(
itemId,
_price
);
}
For me the second way seems way more logical. But i have seen multiple examples of people using the first way. So is there a reason to not do it like the second example? I just want to make sure im not missing an important concept.