Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Danenbm/collapse registry record struct #1

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

danenbm
Copy link
Contributor

@danenbm danenbm commented Feb 27, 2024

Removed the pub data: RegistryData, in both RegistryRecord and ExternalPluginRecord since it doesn't seem to be helping us. Also simplified the iterators from destructuring in the closure to just dereferencing when using.

So combining the two changes simplifies our usage a bit:

let plugin_data = registry
        .iter()
        .find(
            |RegistryRecord {
                 plugin_type: plugin_type_iter,
                 data: _,
             }| *plugin_type_iter == plugin_type,
        )
        .map(
            |RegistryRecord {
                 plugin_type: _,
                 data,
             }| data,
        )
        .ok_or(MplCoreError::PluginNotFound)?;

becomes

let plugin = registry
        .iter()
        .find(|record| record.plugin_type == plugin_type)
        .ok_or(MplCoreError::PluginNotFound)?;

Comment on lines -161 to 160
let registry_data = RegistryData {

let new_registry_record = RegistryRecord {
plugin_type,
offset: old_registry_offset,
authorities: vec![authority.clone()],
};

let size_increase = plugin_size
.checked_add(Key::get_initial_size())
.ok_or(MplCoreError::NumericalOverflow)?
.checked_add(registry_data.clone().try_to_vec()?.len())
.checked_add(new_registry_record.try_to_vec()?.len())
.ok_or(MplCoreError::NumericalOverflow)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This size increase used to be just a RegistryData, but I think it should have been a full RegistryRecord because we are adding a new RegistryRecord to the Vec. Could you double-check this math?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right.

@blockiosaurus blockiosaurus merged commit c98251c into main Feb 27, 2024
6 of 7 checks passed
@blockiosaurus blockiosaurus deleted the danenbm/collapse-registry-record-struct branch February 27, 2024 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants