Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
d7e34051
Commit
d7e34051
authored
Jan 23, 2012
by
Ivan Krasin
Committed by
Russ Cox
Jan 23, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compress/flate: reduce memory pressure at cost of additional arithmetic operation.
R=rsc CC=golang-dev
https://golang.org/cl/5555070
parent
427b5bdd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
23 deletions
+11
-23
deflate.go
src/pkg/compress/flate/deflate.go
+11
-23
No files found.
src/pkg/compress/flate/deflate.go
View file @
d7e34051
...
...
@@ -70,9 +70,10 @@ type compressor struct {
// If hashHead[hashValue] is within the current window, then
// hashPrev[hashHead[hashValue] & windowMask] contains the previous index
// with the same hash value.
chainHead
int
hashHead
[]
int
hashPrev
[]
int
chainHead
int
hashHead
[]
int
hashPrev
[]
int
hashOffset
int
// input window: unprocessed data is window[index:windowEnd]
index
int
...
...
@@ -104,20 +105,7 @@ func (d *compressor) fillDeflate(b []byte) int {
}
else
{
d
.
blockStart
=
skipNever
}
for
i
,
h
:=
range
d
.
hashHead
{
v
:=
h
-
windowSize
if
v
<
-
1
{
v
=
-
1
}
d
.
hashHead
[
i
]
=
v
}
for
i
,
h
:=
range
d
.
hashPrev
{
v
:=
h
-
windowSize
if
v
<
-
1
{
v
=
-
1
}
d
.
hashPrev
[
i
]
=
v
}
d
.
hashOffset
+=
windowSize
}
n
:=
copy
(
d
.
window
[
d
.
windowEnd
:
],
b
)
d
.
windowEnd
+=
n
...
...
@@ -188,7 +176,7 @@ func (d *compressor) findMatch(pos int, prevHead int, prevLength int, lookahead
// hashPrev[i & windowMask] has already been overwritten, so stop now.
break
}
if
i
=
d
.
hashPrev
[
i
&
windowMask
];
i
<
minIndex
||
i
<
0
{
if
i
=
d
.
hashPrev
[
i
&
windowMask
]
-
d
.
hashOffset
;
i
<
minIndex
||
i
<
0
{
break
}
}
...
...
@@ -207,7 +195,7 @@ func (d *compressor) initDeflate() {
d
.
hashHead
=
make
([]
int
,
hashSize
)
d
.
hashPrev
=
make
([]
int
,
windowSize
)
d
.
window
=
make
([]
byte
,
2
*
windowSize
)
fillInts
(
d
.
hashHead
,
-
1
)
d
.
hashOffset
=
1
d
.
tokens
=
make
([]
token
,
maxFlateBlockTokens
,
maxFlateBlockTokens
+
1
)
d
.
length
=
minMatchLength
-
1
d
.
offset
=
0
...
...
@@ -263,7 +251,7 @@ Loop:
d
.
hash
=
(
d
.
hash
<<
hashShift
+
int
(
d
.
window
[
d
.
index
+
2
]))
&
hashMask
d
.
chainHead
=
d
.
hashHead
[
d
.
hash
]
d
.
hashPrev
[
d
.
index
&
windowMask
]
=
d
.
chainHead
d
.
hashHead
[
d
.
hash
]
=
d
.
index
d
.
hashHead
[
d
.
hash
]
=
d
.
index
+
d
.
hashOffset
}
prevLength
:=
d
.
length
prevOffset
:=
d
.
offset
...
...
@@ -274,10 +262,10 @@ Loop:
minIndex
=
0
}
if
d
.
chainHead
>=
minIndex
&&
if
d
.
chainHead
-
d
.
hashOffset
>=
minIndex
&&
(
d
.
fastSkipHashing
!=
skipNever
&&
lookahead
>
minMatchLength
-
1
||
d
.
fastSkipHashing
==
skipNever
&&
lookahead
>
prevLength
&&
prevLength
<
d
.
lazy
)
{
if
newLength
,
newOffset
,
ok
:=
d
.
findMatch
(
d
.
index
,
d
.
chainHead
,
minMatchLength
-
1
,
lookahead
);
ok
{
if
newLength
,
newOffset
,
ok
:=
d
.
findMatch
(
d
.
index
,
d
.
chainHead
-
d
.
hashOffset
,
minMatchLength
-
1
,
lookahead
);
ok
{
d
.
length
=
newLength
d
.
offset
=
newOffset
}
...
...
@@ -310,7 +298,7 @@ Loop:
// Our chain should point to the previous value.
d
.
hashPrev
[
d
.
index
&
windowMask
]
=
d
.
hashHead
[
d
.
hash
]
// Set the head of the hash chain to us.
d
.
hashHead
[
d
.
hash
]
=
d
.
index
d
.
hashHead
[
d
.
hash
]
=
d
.
index
+
d
.
hashOffset
}
}
if
d
.
fastSkipHashing
==
skipNever
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment