Skip to content

Commit

Permalink
invert key1 and key2 to save some memory
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Apr 15, 2024
1 parent 1e52700 commit 03c069f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions types/src/state_store/state_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ impl Drop for Entry {
.lock_and_remove(&module_id.address, &module_id.name),
Path::Resource(struct_tag) => GLOBAL_REGISTRY
.resource_keys
.lock_and_remove(address, struct_tag),
.lock_and_remove(struct_tag, address),
Path::ResourceGroup(struct_tag) => GLOBAL_REGISTRY
.resource_group_keys
.lock_and_remove(address, struct_tag),
.lock_and_remove(struct_tag, address),
}
},
StateKeyInner::TableItem { handle, key } => {
Expand Down Expand Up @@ -332,8 +332,8 @@ static GLOBAL_REGISTRY: Lazy<StateKeyRegistry> = Lazy::new(StateKeyRegistry::new

pub struct StateKeyRegistry {
// FIXME(aldenhu): reverse dimensions to save memory?
resource_keys: TwoLevelRegistry<AccountAddress, StructTag>,
resource_group_keys: TwoLevelRegistry<AccountAddress, StructTag>,
resource_keys: TwoLevelRegistry<StructTag, AccountAddress>,
resource_group_keys: TwoLevelRegistry<StructTag, AccountAddress>,
module_keys: TwoLevelRegistry<AccountAddress, Identifier>,
table_item_keys: TwoLevelRegistry<TableHandle, Vec<u8>>,
raw_keys: TwoLevelRegistry<Vec<u8>, ()>, // for tests only
Expand Down Expand Up @@ -400,7 +400,7 @@ impl StateKey {
}

pub fn resource(address: &AccountAddress, struct_tag: &StructTag) -> Self {
if let Some(entry) = GLOBAL_REGISTRY.resource_keys.try_get(address, struct_tag) {
if let Some(entry) = GLOBAL_REGISTRY.resource_keys.try_get(struct_tag, address) {
return Self(entry);
}

Expand All @@ -412,7 +412,7 @@ impl StateKey {

let entry = GLOBAL_REGISTRY
.resource_keys
.lock_and_get_or_add(address, struct_tag, maybe_add);
.lock_and_get_or_add(struct_tag, address, maybe_add);
Self(entry)
}

Expand All @@ -427,7 +427,7 @@ impl StateKey {
pub fn resource_group(address: &AccountAddress, struct_tag: &StructTag) -> Self {
if let Some(entry) = GLOBAL_REGISTRY
.resource_group_keys
.try_get(address, struct_tag)
.try_get(struct_tag, address)
{
return Self(entry);
}
Expand All @@ -440,7 +440,7 @@ impl StateKey {

let entry = GLOBAL_REGISTRY
.resource_group_keys
.lock_and_get_or_add(address, struct_tag, maybe_add);
.lock_and_get_or_add(struct_tag, address, maybe_add);
Self(entry)
}

Expand Down

0 comments on commit 03c069f

Please sign in to comment.