I am currently in the process of creating a smart contract on T-Sol that will require periodic additions of new elements to a mapping. If these elements are not already present in the mapping, they will be initialized accordingly.
struct Person {
uint age;
string name;
}
mapping(uint16 => Person) testMapping;
I'm wondering which way will be more efficient in terms of gas consumption?
- Option 1
testMapping.getAdd(i, Person(0, ""));
- Option 2
if (!testMapping.exists(i)) {
testMapping[18] = Person(0, "");
}
Is there a better way of initialization?