-
Notifications
You must be signed in to change notification settings - Fork 506
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
Make registry key/value iterators lazy #3260
Conversation
} | ||
}) | ||
return self.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is recursive - not necessarily bad in this scenario but worth calling out if it's not obvious.
idx: 0, | ||
name: vec![0; (info.value_name_max + 1) as usize], | ||
data: Data::new(info.value_data_max as usize), | ||
}) | ||
} | ||
|
||
fn resize(&mut self) -> Result<()> { | ||
let info = get_key_info(self.key)?; | ||
self.name.resize((info.value_name_max + 1) as usize, 0); | ||
self.data = Data::new(info.value_data_max as usize); | ||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal but might be nice to default initialize and then call resize
in the new
method to avoid the redundant initialization here and in the other iterator.
for name in iterator { | ||
if name == "one" { | ||
key.remove_tree("three")?; | ||
key.create("seventy")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it obvious that this requires a larger buffer...
let iterator = key.values()?; | ||
for (name, value) in iterator { | ||
if name == "string" { | ||
key.set_string("string-two", "hello world two")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
After more testing, I've identified a critical issue with key enumeration. Adding a subkey during this process triggers immediate lexical sorting, which can re-order the subkeys mid-enumeration. Since modification of the key isn't supported during enumeration, it's not possible to safely perform the lazy initialization proposed here. Therefore, I'm closing this PR. |
This change updates the key and value iterators to support "forward-lazy" iteration, where the underlying key may change during the iteration process. Previously, the iterators assumed a static state for the registry key but this could lead to panic if keys were modified externally during iteration. The updated iterators now account for potential changes, at the expense of some additional registry queries and/or heap activity.