io: mark some bitstream reading functions as inline
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 12 Aug 2017 09:21:29 +0000 (11:21 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 12 Aug 2017 09:21:29 +0000 (11:21 +0200)
src/io/bitreader.rs
src/io/intcode.rs

index b3e478edf64d4a6832eb09d160d6f3bb7b875871..ea5f27c078d8c4e9cb3aa69bb69eeaa47e3d149e 100644 (file)
@@ -70,6 +70,7 @@ impl<'a> BitReader<'a> {
         }
     }
 
+    #[inline(always)]
     fn refill(&mut self) -> BitReaderResult<()> {
         if self.pos >= self.end { return Err(BitstreamEnd) }
         while self.bits <= 32 {
@@ -106,6 +107,7 @@ impl<'a> BitReader<'a> {
         Ok(())
     }
 
+    #[inline(always)]
     fn read_cache(&mut self, nbits: u8) -> u32 {
         let res = match self.mode {
             BitReaderMode::LE => ((1u64 << nbits) - 1) & self.cache,
@@ -122,6 +124,7 @@ impl<'a> BitReader<'a> {
         res as i32
     }
 
+    #[inline(always)]
     fn skip_cache(&mut self, nbits: u8) {
         match self.mode {
             BitReaderMode::LE => self.cache >>= nbits,
@@ -130,11 +133,13 @@ impl<'a> BitReader<'a> {
         self.bits -= nbits;
     }
 
+    #[inline(always)]
     fn reset_cache(&mut self) {
         self.bits = 0;
         self.cache = 0;
     }
 
+    #[inline(always)]
     pub fn read(&mut self, nbits: u8) -> BitReaderResult<u32> {
         if nbits == 0 { return Ok(0) }
         if nbits > 32 { return Err(TooManyBitsRequested) }
@@ -158,6 +163,7 @@ impl<'a> BitReader<'a> {
         Ok(res)
     }
 
+    #[inline(always)]
     pub fn read_bool(&mut self) -> BitReaderResult<bool> {
         if self.bits < 1 {
             if let Err(err) = self.refill() { return Err(err) }
@@ -168,12 +174,14 @@ impl<'a> BitReader<'a> {
         Ok(res == 1)
     }
 
+    #[inline(always)]
     pub fn peek(&mut self, nbits: u8) -> u32 {
         if nbits > 32 { return 0 }
         if self.bits < nbits { let _ = self.refill(); }
         self.read_cache(nbits)
     }
 
+    #[inline(always)]
     pub fn skip(&mut self, nbits: u32) -> BitReaderResult<()> {
         if self.bits as u32 >= nbits {
             self.skip_cache(nbits as u8);
index 141377dc686f09e16993c958c7e705ada9d210c0..5e35a15a9f8416dec264c2bb2edc942111d1e4f4 100644 (file)
@@ -96,6 +96,7 @@ fn uval_to_sval0pm(uval: u32) -> i32 {
 }
 
 impl<'a> IntCodeReader for BitReader<'a> {
+    #[inline(always)]
     fn read_code(&mut self, t: UintCodeType) -> BitReaderResult<u32> {
         match t {
             UintCodeType::UnaryOnes               => read_unary(self, 0),