summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8b430c9)
raw | patch | inline | side by side (parent: 8b430c9)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 21 Apr 2006 21:40:32 +0000 (21:40 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 21 Apr 2006 21:40:32 +0000 (21:40 +0000) |
src/dom/util/ziptool.cpp | patch | blob | history |
index e6d46557b6d753b4fe939172bca6af8e54952262..b3c5ec9b0f31462190ed882696e595a0a988521f 100644 (file)
--- a/src/dom/util/ziptool.cpp
+++ b/src/dom/util/ziptool.cpp
\r
\r
/**\r
- *\r
+ * This method does the dirty work of dictionary\r
+ * compression. Basically it looks for redundant\r
+ * strings and has the current duplicate refer back\r
+ * to the previous one.\r
*/\r
bool Deflater::compressWindow()\r
{\r
+ unsigned int windowSize = window.size();\r
//### Compress as much of the window as possible\r
int i=0;\r
std::vector<unsigned char>::iterator iter;\r
for (iter=window.begin() ; iter!=window.end() ; iter++)\r
windowBuf[i++] = *iter;\r
\r
- while (windowPos < window.size())\r
+ while (windowPos < windowSize)\r
{\r
//### Find best match, if any\r
unsigned int bestMatchLen = 0;\r
{\r
for (unsigned int lookBack=0 ; lookBack<windowPos-4 ; lookBack++)\r
{\r
- unsigned int lookAhead;\r
- unsigned int lookAheadMax = window.size() - windowPos;\r
- if (lookBack + lookAheadMax >= windowPos)\r
- lookAheadMax = windowPos - lookBack;\r
- if (lookAheadMax > 258)\r
- lookAheadMax = 258;\r
- for (lookAhead = 0 ; lookAhead<lookAheadMax ; lookAhead++)\r
+ unsigned int lookAhead=0;\r
+ unsigned char *wp = &(windowBuf[windowPos]);\r
+ unsigned char *lb = &(windowBuf[lookBack]);\r
+ //Check first char, before continuing with string\r
+ if (*lb++ == *wp++)\r
{\r
- unsigned int pos1 = lookBack + lookAhead;\r
- unsigned int pos2 = windowPos + lookAhead;\r
- if (windowBuf[pos1] != windowBuf[pos2])\r
- break;\r
+ unsigned int lookAheadMax = windowSize - windowPos;\r
+ if (lookBack + lookAheadMax >= windowPos)\r
+ lookAheadMax = windowPos - lookBack;\r
+ if (lookAheadMax > 258)\r
+ lookAheadMax = 258;\r
+ for (lookAhead = 1 ; lookAhead<lookAheadMax ; lookAhead++)\r
+ {\r
+ if (*lb++ != *wp++)\r
+ break;\r
+ }\r
}\r
if (lookAhead > bestMatchLen)\r
{\r