diff --git a/src/logic.rs b/src/logic.rs index 8aaf693..4d07e8d 100644 --- a/src/logic.rs +++ b/src/logic.rs @@ -55,7 +55,7 @@ macro_rules! logic_op { } } - impl<'a> $imp_assign<&'a SmallUint> for $typ { + impl<'a> $imp_assign<&'a $typ> for $typ { fn $fun_assign(&mut self, rhs: &'a $typ) { *self = (&*self).$fun(rhs); } @@ -97,18 +97,18 @@ macro_rules! logic_op { macro_rules! inline_heap_to_inline { - ($fun:tt; $i:ident, $slice:ident) => { + ($fun:ident, $typ:ident, $typ_inner:ident; $i:ident, $slice:ident) => { let mut j = 0u128; for i in 0..4 { j <<= 32; j |= $slice[3 - i] as u128; } - SmallUint(SmallUintType::Inline($i.$fun(j))) + $typ($typ_inner::Inline($i.$fun(j))) } } macro_rules! inline_heap_to_heap { - ($fun_assign:ident; $i:ident, $slice:ident) => { + ($fun_assign:ident, $typ:ident, $typ_inner:ident; $i:ident, $slice:ident) => { let mut retvec = $slice.to_vec(); let mut v = $i; @@ -121,7 +121,7 @@ macro_rules! inline_heap_to_heap { let mut retslice = ManuallyDrop::new(retvec.into_boxed_slice()); - SmallUint(SmallUintType::Heap((retslice.as_mut_ptr(), retslice.len()))) + $typ($typ_inner::Heap((retslice.as_mut_ptr(), retslice.len()))) } } @@ -152,14 +152,14 @@ macro_rules! heap_heap_create_res_longest { macro_rules! heap_heap_return_heap { - ($res:ident) => { + ($typ:ident, $typ_inner:ident; $res:ident) => { let mut slice = ManuallyDrop::new($res.into_boxed_slice()); - SmallUint(SmallUintType::Heap((slice.as_mut_ptr(), slice.len()))) + $typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len()))) } } macro_rules! heap_heap_return_any { - ($res:ident) => { + ($typ:ident, $typ_inner:ident; $res:ident) => { while $res.len() != 1 && $res[$res.len() - 1] == 0 { $res.pop(); } @@ -170,10 +170,10 @@ macro_rules! heap_heap_return_any { r <<= 32; r |= $res[$res.len() - 1 - t] as u128; } - SmallUint(SmallUintType::Inline(r)) + $typ($typ_inner::Inline(r)) } else { let mut slice = ManuallyDrop::new($res.into_boxed_slice()); - SmallUint(SmallUintType::Heap((slice.as_mut_ptr(), slice.len()))) + $typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len()))) } } } @@ -181,25 +181,25 @@ macro_rules! heap_heap_return_any { logic_op! { BitAnd, BitAndAssign, SmallUint, SmallUintType, bitand, bitand_assign; i, j, r, s, slice, slice1, slice2, min, res; - { inline_heap_to_inline! { bitand; i, slice } }, + { inline_heap_to_inline! { bitand, SmallUint, SmallUintType; i, slice } }, { heap_heap_create_res_shortest! { bitand; min, slice1, slice2 } }, - { heap_heap_return_any! { res } } + { heap_heap_return_any! { SmallUint, SmallUintType; res } } } logic_op! { BitOr, BitOrAssign, SmallUint, SmallUintType, bitor, bitor_assign; i, j, r, s, slice, slice1, slice2, min, res; - { inline_heap_to_heap! { bitor_assign; i, slice } }, + { inline_heap_to_heap! { bitor_assign, SmallUint, SmallUintType; i, slice } }, { heap_heap_create_res_longest! { bitor; slice1, slice2, min }}, - { heap_heap_return_heap! { res } } + { heap_heap_return_heap! { SmallUint, SmallUintType; res } } } logic_op! { BitXor, BitXorAssign, SmallUint, SmallUintType, bitxor, bitxor_assign; i, j, r, s, slice, slice1, slice2, min, res; - { inline_heap_to_heap! { bitxor_assign; i, slice } }, + { inline_heap_to_heap! { bitxor_assign, SmallUint, SmallUintType; i, slice } }, { heap_heap_create_res_longest! { bitxor; slice1, slice2, min }}, - { heap_heap_return_any! { res } } + { heap_heap_return_any! { SmallUint, SmallUintType; res } } }