Skip to content

Commit

Permalink
remove a useless clone in PartialSumMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekleog committed Jun 17, 2022
1 parent 3368652 commit 194eafe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/compiler-singlepass/src/codegen_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ impl<'a> FuncGen<'a> {
///
/// More can be introduced with the [`feed_local`](Self::feed_local) method.
pub(crate) fn local_count(&self) -> u32 {
self.local_types.size()
*self.local_types.size()
}

/// Obtain the type of the local or argument at the specified index.
Expand Down
16 changes: 8 additions & 8 deletions lib/types/src/partial_sum_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl<K: Clone + Ord + num_traits::Unsigned + num_traits::CheckedAdd, V> PartialS
/// Note that the result can be greater than `usize::MAX` if eg. `K` is a BigInt type. Cast at your own risk.
///
/// `O(1)`
pub fn size(&self) -> K {
self.size.clone()
pub fn size(&self) -> &K {
&self.size
}

/// Find the value by the index.
Expand Down Expand Up @@ -109,18 +109,18 @@ mod tests {
fn empty_partial_map() {
let map = PartialSumMap::<u32, u32>::new();
assert_eq!(None, map.find(0));
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
}

#[test]
fn basic_function() {
let mut map = PartialSumMap::<u32, u32>::new();
assert_eq!(None, map.max_index());
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
for i in 0..10 {
map.push(1, i).unwrap();
assert_eq!(Some(i), map.max_index());
assert_eq!(i + 1, map.size());
assert_eq!(i + 1, *map.size());
}
for i in 0..10 {
assert_eq!(Some(&i), map.find(i));
Expand All @@ -134,13 +134,13 @@ mod tests {
let mut map = PartialSumMap::<u32, u32>::new();
assert_eq!(Ok(()), map.push(0, 0));
assert_eq!(None, map.max_index());
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
assert_eq!(Ok(()), map.push(10, 42));
assert_eq!(Some(9), map.max_index());
assert_eq!(10, map.size());
assert_eq!(10, *map.size());
assert_eq!(Ok(()), map.push(0, 43));
assert_eq!(Some(9), map.max_index());
assert_eq!(10, map.size());
assert_eq!(10, *map.size());
}

#[test]
Expand Down

0 comments on commit 194eafe

Please sign in to comment.