Skip to content

Commit

Permalink
Optimize Iterator for IIterator<T> (#3476)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 7, 2025
1 parent 1a3f15b commit 35c31ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion crates/libs/bindgen/src/types/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ impl Interface {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
let result = self.Current().ok();
let result = if self.HasCurrent().unwrap_or(false) {
self.Current().ok()
} else {
None
};

if result.is_some() {
self.MoveNext().ok()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
impl<T: windows_core::RuntimeType> Iterator for IIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let result = self.Current().ok();
let result = if self.HasCurrent().unwrap_or(false) { self.Current().ok() } else { None };
if result.is_some() {
self.MoveNext().ok()?;
}
Expand Down
6 changes: 5 additions & 1 deletion crates/tests/bindgen/src/class_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ where
impl<T: windows_core::RuntimeType> Iterator for IIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let result = self.Current().ok();
let result = if self.HasCurrent().unwrap_or(false) {
self.Current().ok()
} else {
None
};
if result.is_some() {
self.MoveNext().ok()?;
}
Expand Down
6 changes: 5 additions & 1 deletion crates/tests/bindgen/src/interface_iterable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ where
impl<T: windows_core::RuntimeType> Iterator for IIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let result = self.Current().ok();
let result = if self.HasCurrent().unwrap_or(false) {
self.Current().ok()
} else {
None
};
if result.is_some() {
self.MoveNext().ok()?;
}
Expand Down

0 comments on commit 35c31ad

Please sign in to comment.