File tree 4 files changed +58
-6
lines changed
4 files changed +58
-6
lines changed Original file line number Diff line number Diff line change 1
1
language : rust
2
- rust : stable
2
+
3
+ matrix :
4
+ include :
5
+ - rust : nightly
6
+ env : FEATURES=reverse_bits
7
+ - rust : nightly
8
+ env : FEATURES=''
9
+ - rust : stable
10
+ - rust : beta
11
+
12
+ script :
13
+ - cargo build --features "$FEATURES"
14
+ - cargo bench --features "$FEATURES"
Original file line number Diff line number Diff line change @@ -13,3 +13,9 @@ categories = ["data-structures"]
13
13
[dependencies ]
14
14
num-traits = " 0.2.1"
15
15
serde = { version =" 1.0" , features =[" derive" ], optional =true }
16
+
17
+ [dev-dependencies ]
18
+ rand = " 0.5.0"
19
+
20
+ [features ]
21
+ reverse_bits = []
Original file line number Diff line number Diff line change
1
+ #![ feature( test) ]
2
+
3
+ extern crate vob;
4
+ extern crate test;
5
+ extern crate rand;
6
+
7
+ use rand:: Rng ;
8
+ use test:: Bencher ;
9
+ use vob:: * ;
10
+
11
+
12
+ #[ bench]
13
+ fn from_bytes ( b : & mut Bencher ) {
14
+ let mut rng = rand:: thread_rng ( ) ;
15
+ let mut source = [ 0u8 ; 1024 ] ;
16
+ rng. fill ( & mut source) ;
17
+
18
+ b. iter ( || {
19
+ Vob :: from_bytes ( & source)
20
+ } ) ;
21
+ }
Original file line number Diff line number Diff line change
1
+ #![ cfg_attr( feature = "reverse_bits" , 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
//
@@ -160,6 +161,9 @@ impl Vob<usize> {
160
161
/// Create a Vob from a `u8` slice. The most significant bit of each byte comes first in the
161
162
/// resulting Vob.
162
163
///
164
+ /// If the optional feature `reverse_bits` is enabled (and you're running nightly)
165
+ /// it will use the new `reverse_bits` method.
166
+ ///
163
167
/// # Examples
164
168
///
165
169
/// ```
@@ -186,12 +190,21 @@ impl Vob<usize> {
186
190
continue ;
187
191
}
188
192
let b = slice[ off] ;
189
- if b != 0 {
190
- let mut rb: u8 = 0 ; // the byte b with its bits in reverse order
191
- for k in 0 ..8 {
192
- rb |= ( ( b >> k) & 1 ) << ( 8 - k - 1 ) ;
193
+ #[ cfg( not( feature = "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
+ }
193
203
}
194
- w |= ( rb as usize ) << ( j * 8 ) ;
204
+ }
205
+ #[ cfg( feature = "reverse_bits" ) ]
206
+ {
207
+ w |= ( b. reverse_bits ( ) as usize ) << ( j * 8 ) ;
195
208
}
196
209
}
197
210
v. vec . push ( w) ;
You can’t perform that action at this time.
0 commit comments