File tree 5 files changed +47
-13
lines changed
5 files changed +47
-13
lines changed Original file line number Diff line number Diff line change 1
1
language : rust
2
2
3
- matrix :
4
- include :
5
- - rust : nightly
6
- env : FEATURES=unsafe_internals
7
- - rust : nightly
8
- env : FEATURES=''
9
- - rust : stable
10
- - rust : beta
3
+ rust :
4
+ - stable
5
+ - nightly
6
+ env :
7
+ - FEATURES=''
8
+ - FEATURES='unsafe_internals'
11
9
12
10
before_script :
13
11
- rustup component add rustfmt-preview
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ readme = "README.md"
10
10
license = " Apache-2.0 OR MIT"
11
11
categories = [" data-structures" ]
12
12
13
+ [build-dependencies ]
14
+ rustc_version = " 0.2"
15
+
13
16
[dependencies ]
14
17
num-traits = " 0.2.1"
15
18
serde = { version =" 1.0" , features =[" derive" ], optional =true }
Original file line number Diff line number Diff line change @@ -101,3 +101,12 @@ fn and(bench: &mut Bencher) {
101
101
a. and ( & b) ;
102
102
} ) ;
103
103
}
104
+
105
+ #[ bench]
106
+ fn from_bytes ( b : & mut Bencher ) {
107
+ let mut rng = rand:: thread_rng ( ) ;
108
+ let mut source = [ 0u8 ; 1024 ] ;
109
+ rng. fill ( & mut source) ;
110
+
111
+ b. iter ( || Vob :: from_bytes ( & source) ) ;
112
+ }
Original file line number Diff line number Diff line change
1
+ extern crate rustc_version;
2
+
3
+ use rustc_version:: { version_meta, Channel } ;
4
+
5
+ fn main ( ) {
6
+ // Set features depending on channel
7
+ if let Channel :: Nightly = version_meta ( ) . unwrap ( ) . channel {
8
+ println ! ( "cargo:rustc-cfg=nightly" ) ;
9
+ // Nightly supports https://github.com/rust-lang/rust/issues/48763
10
+ println ! ( "cargo:rustc-cfg=reverse_bits" ) ;
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ #![ cfg_attr( nightly, feature( reverse_bits) ) ]
1
2
// Copyright (c) 2018 King's College London created by the Software Development Team
2
3
// <http://soft-dev.org/>
3
4
//
@@ -162,6 +163,8 @@ impl Vob<usize> {
162
163
/// Create a Vob from a `u8` slice. The most significant bit of each byte comes first in the
163
164
/// resulting Vob.
164
165
///
166
+ /// If you are running nightly, this method will use the new `reverse_bits` intrinsic.
167
+ ///
165
168
/// # Examples
166
169
///
167
170
/// ```
@@ -187,12 +190,21 @@ impl Vob<usize> {
187
190
continue ;
188
191
}
189
192
let b = slice[ off] ;
190
- if b != 0 {
191
- let mut rb: u8 = 0 ; // the byte b with its bits in reverse order
192
- for k in 0 ..8 {
193
- rb |= ( ( b >> k) & 1 ) << ( 8 - k - 1 ) ;
193
+ #[ cfg( not( reverse_bits) ) ]
194
+ {
195
+ if b != 0 {
196
+ {
197
+ let mut rb: u8 = 0 ; // the byte b with its bits in reverse order
198
+ for k in 0 ..8 {
199
+ rb |= ( ( b >> k) & 1 ) << ( 8 - k - 1 ) ;
200
+ }
201
+ w |= ( rb as usize ) << ( j * 8 ) ;
202
+ }
194
203
}
195
- w |= ( rb as usize ) << ( j * 8 ) ;
204
+ }
205
+ #[ cfg( reverse_bits) ]
206
+ {
207
+ w |= ( b. reverse_bits ( ) as usize ) << ( j * 8 ) ;
196
208
}
197
209
}
198
210
v. vec . push ( w) ;
You can’t perform that action at this time.
0 commit comments