Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Created April 24, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raineorshine/5816c7f647e0090fc3ac52b9d036bb99 to your computer and use it in GitHub Desktop.
Save raineorshine/5816c7f647e0090fc3ac52b9d036bb99 to your computer and use it in GitHub Desktop.
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