Commit 2450cf4 1 parent 0a75a2c commit 2450cf4 Copy full SHA for 2450cf4
File tree 3 files changed +22
-9
lines changed
3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ logging = ["deku_derive/logging", "log"]
27
27
const_generics = []
28
28
# # Enable container.read_cache by default when a `Container` is created
29
29
read_cache = []
30
+ # # Disable writing bits, adding performance to writing bytes
31
+ # #
32
+ # # This is especially important in order to inline writer::write_bytes(..) and DekuWriter::to_writer(..)
33
+ # # whenever possible
34
+ write_bytes_only = []
30
35
31
36
[dependencies ]
32
37
deku_derive = { version = " ^0.16.0" , path = " deku-derive" , default-features = false }
Original file line number Diff line number Diff line change @@ -647,7 +647,7 @@ macro_rules! ImplDekuWrite {
647
647
648
648
// Only have `endian`, return all input
649
649
impl DekuWrite <Endian > for $typ {
650
- #[ inline( always ) ]
650
+ #[ inline]
651
651
fn write(
652
652
& self ,
653
653
output: & mut BitVec <u8 , Msb0 >,
@@ -663,7 +663,7 @@ macro_rules! ImplDekuWrite {
663
663
}
664
664
665
665
impl DekuWriter <Endian > for $typ {
666
- #[ inline( always ) ]
666
+ #[ inline]
667
667
fn to_writer<W : Write >(
668
668
& self ,
669
669
writer: & mut Writer <W >,
Original file line number Diff line number Diff line change @@ -56,17 +56,25 @@ impl<W: Write> Writer<W> {
56
56
pub fn write_bytes ( & mut self , buf : & [ u8 ] ) -> Result < ( ) , DekuError > {
57
57
#[ cfg( feature = "logging" ) ]
58
58
log:: trace!( "writing {} bytes" , buf. len( ) ) ;
59
- if !self . leftover . is_empty ( ) {
60
- #[ cfg( feature = "logging" ) ]
61
- log:: trace!( "leftover exists" ) ;
62
- // TODO: we could check here and only send the required bits to finish the byte?
63
- // (instead of sending the entire thing)
64
- self . write_bits ( & mut BitVec :: from_slice ( buf) ) ?;
65
- } else {
59
+
60
+ if cfg ! ( feature = "write_bytes_only" ) {
66
61
if let Err ( _) = self . inner . write_all ( buf) {
67
62
return Err ( DekuError :: WriteError ) ;
68
63
}
69
64
self . bits_written = buf. len ( ) * 8 ;
65
+ } else {
66
+ if self . leftover . is_empty ( ) {
67
+ if let Err ( _) = self . inner . write_all ( buf) {
68
+ return Err ( DekuError :: WriteError ) ;
69
+ }
70
+ self . bits_written = buf. len ( ) * 8 ;
71
+ } else {
72
+ #[ cfg( feature = "logging" ) ]
73
+ log:: trace!( "leftover exists" ) ;
74
+ // TODO: we could check here and only send the required bits to finish the byte?
75
+ // (instead of sending the entire thing)
76
+ self . write_bits ( & mut BitVec :: from_slice ( buf) ) ?;
77
+ }
70
78
}
71
79
72
80
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments