Skip to content

Commit

Permalink
Use if-let instead of match
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Aug 28, 2023
1 parent 7fe7862 commit 65cfd95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
30 changes: 14 additions & 16 deletions libwasmvm/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ impl GoIter {
}

pub fn next(&mut self) -> BackendResult<Option<Record>> {
let next = match self.vtable.next {
Some(f) => f,
None => {
let result = Err(BackendError::unknown(
"iterator vtable function 'next' not set",
));
return (result, GasInfo::free());
}
let next = if let Some(f) = self.vtable.next {
f
} else {
let result = Err(BackendError::unknown(
"iterator vtable function 'next' not set",
));
return (result, GasInfo::free());
};

let mut output_key = UnmanagedVector::default();
Expand Down Expand Up @@ -140,14 +139,13 @@ impl GoIter {
>,
fn_name: &str,
) -> BackendResult<Option<Vec<u8>>> {
let next = match next_fn {
Some(f) => f,
None => {
let result = Err(BackendError::unknown(format!(
"iterator vtable function '{fn_name}' not set"
)));
return (result, GasInfo::free());
}
let next = if let Some(f) = next_fn {
f
} else {
let result = Err(BackendError::unknown(format!(
"iterator vtable function '{fn_name}' not set"
)));
return (result, GasInfo::free());
};

let mut output = UnmanagedVector::default();
Expand Down
45 changes: 21 additions & 24 deletions libwasmvm/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,38 @@ impl Storage for GoStorage {
}

fn next(&mut self, iterator_id: u32) -> BackendResult<Option<Record>> {
let iterator = match self.iterators.get_mut(&iterator_id) {
Some(i) => i,
None => {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
)
}
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
);
};
iterator.next()
}

fn next_key(&mut self, iterator_id: u32) -> BackendResult<Option<Vec<u8>>> {
let iterator = match self.iterators.get_mut(&iterator_id) {
Some(i) => i,
None => {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
)
}
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
);
};

iterator.next_key()
}

fn next_value(&mut self, iterator_id: u32) -> BackendResult<Option<Vec<u8>>> {
let iterator = match self.iterators.get_mut(&iterator_id) {
Some(i) => i,
None => {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
)
}
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
);
};

iterator.next_value()
Expand Down

0 comments on commit 65cfd95

Please sign in to comment.