@@ -771,15 +771,7 @@ impl<T: sealed::Context> Features<T> {
771
771
// unknown features.
772
772
self . flags . iter ( ) . enumerate ( ) . any ( |( i, & byte) | {
773
773
const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
774
- const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
775
- let unknown_features = if i < other. flags . len ( ) {
776
- // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
777
- !( other. flags [ i]
778
- | ( ( other. flags [ i] >> 1 ) & REQUIRED_FEATURES )
779
- | ( ( other. flags [ i] << 1 ) & OPTIONAL_FEATURES ) )
780
- } else {
781
- 0b11_11_11_11
782
- } ;
774
+ let unknown_features = self . unknown_features_at_position ( other, i) ;
783
775
( byte & ( REQUIRED_FEATURES & unknown_features) ) != 0
784
776
} )
785
777
}
@@ -790,17 +782,7 @@ impl<T: sealed::Context> Features<T> {
790
782
// Bitwise AND-ing with all even bits set except for known features will select required
791
783
// unknown features.
792
784
self . flags . iter ( ) . enumerate ( ) . for_each ( |( i, & byte) | {
793
- const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
794
- const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
795
- let unknown_features = if i < other. flags . len ( ) {
796
- // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
797
- !( other. flags [ i]
798
- | ( ( other. flags [ i] >> 1 ) & REQUIRED_FEATURES )
799
- | ( ( other. flags [ i] << 1 ) & OPTIONAL_FEATURES ) )
800
- } else {
801
- 0b11_11_11_11
802
- } ;
803
-
785
+ let unknown_features = self . unknown_features_at_position ( other, i) ;
804
786
if byte & unknown_features != 0 {
805
787
for bit in ( 0 ..8 ) . step_by ( 2 ) {
806
788
if byte >> bit & 1 == 1 {
@@ -813,6 +795,19 @@ impl<T: sealed::Context> Features<T> {
813
795
unknown_bits
814
796
}
815
797
798
+ pub ( crate ) fn unknown_features_at_position ( & self , other : & Self , index : usize ) -> u8 {
799
+ const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
800
+ const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
801
+ if index < other. flags . len ( ) {
802
+ // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
803
+ !( other. flags [ index]
804
+ | ( ( other. flags [ index] >> 1 ) & REQUIRED_FEATURES )
805
+ | ( ( other. flags [ index] << 1 ) & OPTIONAL_FEATURES ) )
806
+ } else {
807
+ 0b11_11_11_11
808
+ }
809
+ }
810
+
816
811
/// Returns true if this `Features` object contains unknown feature flags which are set as
817
812
/// "required".
818
813
pub fn requires_unknown_bits ( & self ) -> bool {
0 commit comments