Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
contract MyContract {
User user;
mapping (address => User) public users;
uint40 time; // cast to 5 bytes - packed with user
address addr1; // 20 bytes - packed with time
address addr2; // 20 bytes - unpacked, one slot
struct User {
uint40 time; // cast to 5 bytes - packed with user
address addr1; // 20 bytes - packed with time
address addr2; // 20 bytes - unpacked, one slot
}
// 45510 / 15510
function setVars() {
time = uint40(now);
addr1 = this;
addr2 = this;
}
// 45616 / 15616
function setUser() {
user = User({
time: uint40(now),
addr1: this,
addr2: this
});
}
// 45727 / 15727
function setUserMapping() {
users[this] = User({
time: uint40(now),
addr1: this,
addr2: this
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.