Skip to content

Commit 22572d1

Browse files
committed
remove as conversion and refactor
1 parent e551f25 commit 22572d1

File tree

8 files changed

+262
-55
lines changed

8 files changed

+262
-55
lines changed

packages/kit/src/ext/cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn fcmp<T>(lhs: &T, rhs: &T) -> Ordering
66
where
77
T: Float,
88
{
9-
match lhs.partial_cmp(&rhs) {
9+
match lhs.partial_cmp(rhs) {
1010
Some(ordering) => ordering,
1111
None => {
1212
if lhs.is_nan() {

packages/kit/src/ext/stats.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525
T: Num,
2626
F: FnMut(&T, &T) -> Ordering,
2727
{
28-
if data.len() == 0 {
28+
if data.is_empty() {
2929
return None;
3030
}
3131
data.sort_by(compare);
@@ -60,9 +60,9 @@ where
6060
// https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
6161
for idx in 1..len {
6262
if data[candidate] == data[idx] {
63-
count = count + 1;
63+
count += 1;
6464
} else {
65-
count = count - 1;
65+
count -= 1;
6666
}
6767
if count == 0 {
6868
candidate = idx;
@@ -73,7 +73,7 @@ where
7373
count = 0;
7474
for idx in 0..len {
7575
if data[candidate] == data[idx] {
76-
count = count + 1;
76+
count += 1;
7777
}
7878
}
7979

packages/vm/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl InMemoryCache {
2525

2626
/// Looks up a module in the cache and creates a new module
2727
pub fn load(&mut self, checksum: &Checksum) -> Option<Module> {
28-
self.modules.get(checksum).map(|m| m.clone())
28+
self.modules.get(checksum).cloned()
2929
}
3030
}
3131

packages/vm/src/calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where
3737

3838
function.call().map_err(|runtime_err| {
3939
if let Ok(err) = runtime_err.downcast::<Error>() {
40-
return err.clone();
40+
return err;
4141
}
4242

4343
match get_remaining_points(&instance) {

packages/vm/src/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum Error {
2424
UninitializedContextData = 15, // Error while getting uninitialized context data.
2525
ChecksumLengthNotMatch = 16, // Checksum not of intended length.
2626
DataLengthOutOfBound = 17, // Data length is out of bound.
27+
ConvertTypeOutOfBound = 18, // Error while try to convert type.
2728
// Host-generated errors while interacting with OEI.
2829
WrongPeriodActionError = 128, // OEI action to invoke is not available.
2930
TooManyExternalDataError = 129, // Too many external data requests.
@@ -39,6 +40,6 @@ pub enum Error {
3940
impl std::error::Error for Error {}
4041
impl Display for Error {
4142
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42-
write!(f, "{}", self)
43+
write!(f, "{:?}", self)
4344
}
4445
}

0 commit comments

Comments
 (0)