[x265] [PATCH 2 of 7] improvement TEncBinCABAC::writeOut by mask operator and local variant

Min Chen chenm003 at 163.com
Mon Mar 24 20:00:39 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1395687480 25200
# Node ID 928156df5d736de1c8f053ae06d8bb6ce11185e4
# Parent  842aab45735b6b309f6945d4a9f04588ee0e8324
improvement TEncBinCABAC::writeOut by mask operator and local variant

diff -r 842aab45735b -r 928156df5d73 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Mon Mar 24 11:57:41 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Mon Mar 24 11:58:00 2014 -0700
@@ -350,9 +350,10 @@
 void TEncBinCABAC::writeOut()
 {
     uint32_t leadByte = m_low >> (13 + m_bitsLeft);
+    uint32_t low_mask = (uint32_t)(~0) >> (11 + 8 - m_bitsLeft);
 
     m_bitsLeft -= 8;
-    m_low &= 0xffffffffu >> (11 - m_bitsLeft);
+    m_low &= low_mask;
 
     if (leadByte == 0xff)
     {
@@ -360,25 +361,22 @@
     }
     else
     {
-        if (m_numBufferedBytes > 0)
+        uint32_t numBufferedBytes = m_numBufferedBytes;
+        if (numBufferedBytes > 0)
         {
             uint32_t carry = leadByte >> 8;
             uint32_t byteTowrite = m_bufferedByte + carry;
-            m_bufferedByte = leadByte & 0xff;
             m_bitIf->writeByte(byteTowrite);
 
             byteTowrite = (0xff + carry) & 0xff;
-            while (m_numBufferedBytes > 1)
+            while (numBufferedBytes > 1)
             {
                 m_bitIf->writeByte(byteTowrite);
-                m_numBufferedBytes--;
+                numBufferedBytes--;
             }
         }
-        else
-        {
-            m_numBufferedBytes = 1;
-            m_bufferedByte = leadByte;
-        }
+        m_numBufferedBytes = 1;
+        m_bufferedByte = (uint8_t)leadByte;
     }
 }
 



More information about the x265-devel mailing list