summaryrefslogtreecommitdiffstats
path: root/src/dom/util/ziptool.cpp
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2006-04-21 21:40:32 +0000
committerishmal <ishmal@users.sourceforge.net>2006-04-21 21:40:32 +0000
commit4420125dd1a6d9562d9ec4133f0cff90c0d842b3 (patch)
treeb87396654589f7936ddab52ccff82c1c9b2b9833 /src/dom/util/ziptool.cpp
parentMinor cleanup. Sort styleTable. (diff)
downloadinkscape-4420125dd1a6d9562d9ec4133f0cff90c0d842b3.tar.gz
inkscape-4420125dd1a6d9562d9ec4133f0cff90c0d842b3.zip
minor speedup
(bzr r564)
Diffstat (limited to 'src/dom/util/ziptool.cpp')
-rw-r--r--src/dom/util/ziptool.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/dom/util/ziptool.cpp b/src/dom/util/ziptool.cpp
index e6d46557b..b3c5ec9b0 100644
--- a/src/dom/util/ziptool.cpp
+++ b/src/dom/util/ziptool.cpp
@@ -1261,17 +1261,21 @@ void Deflater::encodeDistStatic(unsigned int len, unsigned int dist)
/**
- *
+ * This method does the dirty work of dictionary
+ * compression. Basically it looks for redundant
+ * strings and has the current duplicate refer back
+ * to the previous one.
*/
bool Deflater::compressWindow()
{
+ unsigned int windowSize = window.size();
//### Compress as much of the window as possible
int i=0;
std::vector<unsigned char>::iterator iter;
for (iter=window.begin() ; iter!=window.end() ; iter++)
windowBuf[i++] = *iter;
- while (windowPos < window.size())
+ while (windowPos < windowSize)
{
//### Find best match, if any
unsigned int bestMatchLen = 0;
@@ -1280,18 +1284,22 @@ bool Deflater::compressWindow()
{
for (unsigned int lookBack=0 ; lookBack<windowPos-4 ; lookBack++)
{
- unsigned int lookAhead;
- unsigned int lookAheadMax = window.size() - windowPos;
- if (lookBack + lookAheadMax >= windowPos)
- lookAheadMax = windowPos - lookBack;
- if (lookAheadMax > 258)
- lookAheadMax = 258;
- for (lookAhead = 0 ; lookAhead<lookAheadMax ; lookAhead++)
+ unsigned int lookAhead=0;
+ unsigned char *wp = &(windowBuf[windowPos]);
+ unsigned char *lb = &(windowBuf[lookBack]);
+ //Check first char, before continuing with string
+ if (*lb++ == *wp++)
{
- unsigned int pos1 = lookBack + lookAhead;
- unsigned int pos2 = windowPos + lookAhead;
- if (windowBuf[pos1] != windowBuf[pos2])
- break;
+ unsigned int lookAheadMax = windowSize - windowPos;
+ if (lookBack + lookAheadMax >= windowPos)
+ lookAheadMax = windowPos - lookBack;
+ if (lookAheadMax > 258)
+ lookAheadMax = 258;
+ for (lookAhead = 1 ; lookAhead<lookAheadMax ; lookAhead++)
+ {
+ if (*lb++ != *wp++)
+ break;
+ }
}
if (lookAhead > bestMatchLen)
{