File tree 4 files changed +47
-7
lines changed
4 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 1
1
language : rust
2
2
3
+ rust :
4
+ - stable
5
+ - beta
6
+ - nightly
7
+ env :
8
+ - FEATURES=unsafe_internals
9
+ - FEATURES=reverse_bits
10
+ - FEATURES=reverse_bits unsafe_internals
11
+
3
12
matrix :
13
+ # Exclude combinations with unstable features for stable and beta
14
+ exclude :
15
+ - rust : stable
16
+ - rust : beta
4
17
include :
5
- - rust : nightly
6
- env : FEATURES=unsafe_internals
7
18
- rust : nightly
8
19
env : FEATURES=''
9
20
- rust : stable
21
+ env : FEATURES=''
10
22
- rust : beta
23
+ env : FEATURES=''
11
24
12
25
script :
13
26
- cargo build --features "$FEATURES"
Original file line number Diff line number Diff line change @@ -19,3 +19,4 @@ rand = "0.5"
19
19
20
20
[features ]
21
21
unsafe_internals = []
22
+ reverse_bits = []
Original file line number Diff line number Diff line change 3
3
#[ macro_use]
4
4
extern crate vob;
5
5
extern crate test;
6
+ extern crate rand;
6
7
7
8
use test:: Bencher ;
8
9
use vob:: * ;
10
+ use rand:: Rng ;
9
11
10
12
const N : usize = 100000 ;
11
13
@@ -49,3 +51,14 @@ fn extend_vob_not_aligned(b: &mut Bencher) {
49
51
vector. extend_from_vob ( & source)
50
52
} ) ;
51
53
}
54
+
55
+ #[ bench]
56
+ fn from_bytes ( b : & mut Bencher ) {
57
+ let mut rng = rand:: thread_rng ( ) ;
58
+ let mut source = [ 0u8 ; 1024 ] ;
59
+ rng. fill ( & mut source) ;
60
+
61
+ b. iter ( || {
62
+ Vob :: from_bytes ( & source)
63
+ } ) ;
64
+ }
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
//
@@ -162,6 +163,9 @@ 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 the optional feature `reverse_bits` is enabled (and you're running nightly)
167
+ /// it will use the new `reverse_bits` method.
168
+ ///
165
169
/// # Examples
166
170
///
167
171
/// ```
@@ -188,12 +192,21 @@ impl Vob<usize> {
188
192
continue ;
189
193
}
190
194
let b = slice[ off] ;
191
- if b != 0 {
192
- let mut rb: u8 = 0 ; // the byte b with its bits in reverse order
193
- for k in 0 ..8 {
194
- rb |= ( ( b >> k) & 1 ) << ( 8 - k - 1 ) ;
195
+ #[ cfg( not( feature = "reverse_bits" ) ) ]
196
+ {
197
+ if b != 0 {
198
+ {
199
+ let mut rb: u8 = 0 ; // the byte b with its bits in reverse order
200
+ for k in 0 ..8 {
201
+ rb |= ( ( b >> k) & 1 ) << ( 8 - k - 1 ) ;
202
+ }
203
+ w |= ( rb as usize ) << ( j * 8 ) ;
204
+ }
195
205
}
196
- w |= ( rb as usize ) << ( j * 8 ) ;
206
+ }
207
+ #[ cfg( feature = "reverse_bits" ) ]
208
+ {
209
+ w |= ( b. reverse_bits ( ) as usize ) << ( j * 8 ) ;
197
210
}
198
211
}
199
212
v. vec . push ( w) ;
You can’t perform that action at this time.
0 commit comments