src/lib/CDRParser.cpp | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
New commits: commit 2a5b92b43336c3e0b82ffad6b06b8623d7007761 Author: David Tardon <[email protected]> Date: Thu Nov 20 21:41:16 2014 +0100 optimize repeated seeks This speeds up parsing of a pathological case of a broken file from 0m29.644s to 0m0.028s. Change-Id: I438d8d3bfd84d3d52e8de18b2680a43948cda3ed diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp index 9a69913..2b70a2c 100644 --- a/src/lib/CDRParser.cpp +++ b/src/lib/CDRParser.cpp @@ -2596,22 +2596,13 @@ void libcdr::CDRParser::readStlt(librevenge::RVNGInputStream *input, unsigned le } unsigned numIntervals = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numIntervals 0x%x\n", numIntervals)); - for (i=0; i<numIntervals; ++i) - { - input->seek(52, librevenge::RVNG_SEEK_CUR); - } + input->seek(52 * static_cast<long>(numIntervals), librevenge::RVNG_SEEK_CUR); unsigned numSet5s = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numSet5s 0x%x\n", numSet5s)); - for (i=0; i<numSet5s; ++i) - { - input->seek(152, librevenge::RVNG_SEEK_CUR); - } + input->seek(152 * static_cast<long>(numSet5s), librevenge::RVNG_SEEK_CUR); unsigned numTabs = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numTabs 0x%x\n", numTabs)); - for (i=0; i<numTabs; ++i) - { - input->seek(784, librevenge::RVNG_SEEK_CUR); - } + input->seek(784 * static_cast<long>(numTabs), librevenge::RVNG_SEEK_CUR); unsigned numBullets = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numBullets 0x%x\n", numBullets)); for (i=0; i<numBullets; ++i) @@ -2649,18 +2640,13 @@ void libcdr::CDRParser::readStlt(librevenge::RVNGInputStream *input, unsigned le } unsigned numHypens = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numHypens 0x%x\n", numHypens)); - for (i=0; i<numHypens; ++i) - { - input->seek(32, librevenge::RVNG_SEEK_CUR); - if (m_version >= 1300) - input->seek(4, librevenge::RVNG_SEEK_CUR); - } + long hypensLen = 32; + if (m_version >= 1300) + hypensLen += 4; + input->seek(hypensLen * static_cast<long>(numHypens), librevenge::RVNG_SEEK_CUR); unsigned numDropcaps = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numDropcaps 0x%x\n", numDropcaps)); - for (i=0; i<numDropcaps; ++i) - { - input->seek(28, librevenge::RVNG_SEEK_CUR); - } + input->seek(28 * static_cast<long>(numDropcaps), librevenge::RVNG_SEEK_CUR); try { bool set11Flag(false); @@ -2669,10 +2655,7 @@ void libcdr::CDRParser::readStlt(librevenge::RVNGInputStream *input, unsigned le set11Flag = true; unsigned numSet11s = readU32(input); CDR_DEBUG_MSG(("CDRParser::readStlt numSet11s 0x%x\n", numSet11s)); - for (i=0; i<numSet11s; ++i) - { - input->seek(12, librevenge::RVNG_SEEK_CUR); - } + input->seek(12 * static_cast<long>(numSet11s), librevenge::RVNG_SEEK_CUR); } std::map<unsigned, CDRStltRecord> styles; for (i=0; i<numRecords; ++i) commit d08b5c8a09190852e21f8a2ae4b1720f13dbfbc4 Author: David Tardon <[email protected]> Date: Thu Nov 20 20:17:08 2014 +0100 avoid extra big allocation Change-Id: Ibb22de59d17a85e8b0a8df8be277643fc9ba7f52 diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp index d9d66c9..9a69913 100644 --- a/src/lib/CDRParser.cpp +++ b/src/lib/CDRParser.cpp @@ -2044,6 +2044,8 @@ void libcdr::CDRParser::readLoda(librevenge::RVNGInputStream *input, unsigned le long startPosition = input->tell(); unsigned chunkLength = readUnsigned(input); unsigned numOfArgs = readUnsigned(input); + if (numOfArgs > length / 4) // avoid extra big allocation in case of a broken file + numOfArgs = length / 4; unsigned startOfArgs = readUnsigned(input); unsigned startOfArgTypes = readUnsigned(input); unsigned chunkType = readUnsigned(input); _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
