[Libreoffice-commits] core.git: oox/source

David Tardon dtardon at redhat.com
Mon Dec 14 12:25:05 PST 2015


 oox/source/ole/vbaexport.cxx |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

New commits:
commit fd94964ad6611d7f20523272fe6752d38e3aec88
Author: David Tardon <dtardon at redhat.com>
Date:   Mon Dec 14 21:17:43 2015 +0100

    don't be creative and use a simple lookup table
    
    The original code breaks at least in optimized build on Fedora x86,
    because there nBits for 256 is computed as 9, not 8.
    
    Change-Id: Ib157c415bc9e231bf7fd544349810e6bc83c8fcc

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 2cb2fea..2041d50 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -9,6 +9,7 @@
 
 #include <sal/config.h>
 
+#include <cassert>
 #include <cmath>
 #include <random>
 
@@ -324,8 +325,26 @@ void VBACompressionChunk::CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOf
         sal_uInt16& rBitCount, sal_uInt16& rMaximumLength)
 {
     sal_uInt16 nDifference = mnDecompressedCurrent;
-    sal_uInt16 nBitCount = std::ceil(std::log(nDifference)/std::log(2));
-    rBitCount = std::max<sal_uInt16>(nBitCount, 4);
+    assert(nDifference <= 4096);
+    assert(nDifference >= 1);
+    if (nDifference >= 2049)
+        rBitCount = 12;
+    else if (nDifference >= 1025)
+        rBitCount = 11;
+    else if (nDifference >= 513)
+        rBitCount = 10;
+    else if (nDifference >= 257)
+        rBitCount = 9;
+    else if (nDifference >= 129)
+        rBitCount = 8;
+    else if (nDifference >= 65)
+        rBitCount = 7;
+    else if (nDifference >= 33)
+        rBitCount = 6;
+    else if (nDifference >= 17)
+        rBitCount = 5;
+    else
+        rBitCount = 4;
     rLengthMask = 0xffff >> rBitCount;
     rOffsetMask = ~rLengthMask;
     rMaximumLength = rLengthMask + 3;


More information about the Libreoffice-commits mailing list