Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
13eff752
Commit
13eff752
authored
13 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Keep a stack of free segments to reduce allocations.
parent
337c1c8a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/net/sf/briar/transport/IncomingErrorCorrectionLayerImpl.java
+21
-5
21 additions, 5 deletions
.../sf/briar/transport/IncomingErrorCorrectionLayerImpl.java
with
21 additions
and
5 deletions
components/net/sf/briar/transport/IncomingErrorCorrectionLayerImpl.java
+
21
−
5
View file @
13eff752
package
net.sf.briar.transport
;
package
net.sf.briar.transport
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
net.sf.briar.api.FormatException
;
import
net.sf.briar.api.FormatException
;
import
net.sf.briar.api.transport.Segment
;
import
net.sf.briar.api.transport.Segment
;
...
@@ -15,6 +17,7 @@ class IncomingErrorCorrectionLayerImpl implements IncomingErrorCorrectionLayer {
...
@@ -15,6 +17,7 @@ class IncomingErrorCorrectionLayerImpl implements IncomingErrorCorrectionLayer {
private
final
int
n
,
k
;
private
final
int
n
,
k
;
private
final
Map
<
Long
,
Integer
>
discardCounts
;
private
final
Map
<
Long
,
Integer
>
discardCounts
;
private
final
Map
<
Long
,
Segment
[]>
segmentSets
;
private
final
Map
<
Long
,
Segment
[]>
segmentSets
;
private
final
ArrayList
<
Segment
>
freeSegments
;
IncomingErrorCorrectionLayerImpl
(
IncomingEncryptionLayer
in
,
IncomingErrorCorrectionLayerImpl
(
IncomingEncryptionLayer
in
,
ErasureDecoder
decoder
,
int
n
,
int
k
)
{
ErasureDecoder
decoder
,
int
n
,
int
k
)
{
...
@@ -24,24 +27,37 @@ class IncomingErrorCorrectionLayerImpl implements IncomingErrorCorrectionLayer {
...
@@ -24,24 +27,37 @@ class IncomingErrorCorrectionLayerImpl implements IncomingErrorCorrectionLayer {
this
.
k
=
k
;
this
.
k
=
k
;
discardCounts
=
new
HashMap
<
Long
,
Integer
>();
discardCounts
=
new
HashMap
<
Long
,
Integer
>();
segmentSets
=
new
HashMap
<
Long
,
Segment
[]>();
segmentSets
=
new
HashMap
<
Long
,
Segment
[]>();
freeSegments
=
new
ArrayList
<
Segment
>();
}
}
public
boolean
readFrame
(
Frame
f
,
FrameWindow
window
)
throws
IOException
,
public
boolean
readFrame
(
Frame
f
,
FrameWindow
window
)
throws
IOException
,
InvalidDataException
{
InvalidDataException
{
// Free any segment sets that have been removed from the window
// Free any segment sets that have been removed from the window
Iterator
<
Long
>
it
=
segmentSets
.
keySet
().
iterator
();
Iterator
<
Entry
<
Long
,
Segment
[]>>
it
=
segmentSets
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
if
(!
window
.
contains
(
it
.
next
()))
it
.
remove
();
while
(
it
.
hasNext
())
{
Entry
<
Long
,
Segment
[]>
e
=
it
.
next
();
if
(!
window
.
contains
(
e
.
getKey
()))
{
it
.
remove
();
for
(
Segment
s
:
e
.
getValue
())
if
(
s
!=
null
)
freeSegments
.
add
(
s
);
}
}
// Free any discard counts that are no longer too high for the window
// Free any discard counts that are no longer too high for the window
Iterator
<
Long
>
it1
=
discardCounts
.
keySet
().
iterator
();
Iterator
<
Long
>
it1
=
discardCounts
.
keySet
().
iterator
();
while
(
it1
.
hasNext
())
if
(!
window
.
isTooHigh
(
it1
.
next
()))
it1
.
remove
();
while
(
it1
.
hasNext
())
if
(!
window
.
isTooHigh
(
it1
.
next
()))
it1
.
remove
();
// FIXME: Unnecessary allocation
// Grab a free segment, or allocate one if necessary
Segment
s
=
new
SegmentImpl
();
Segment
s
;
int
free
=
freeSegments
.
size
();
if
(
free
==
0
)
s
=
new
SegmentImpl
();
else
s
=
freeSegments
.
remove
(
free
-
1
);
// Read segments until a frame can be decoded
// Read segments until a frame can be decoded
while
(
true
)
{
while
(
true
)
{
// Read segments until a segment in the window is returned
// Read segments until a segment in the window is returned
long
frameNumber
;
long
frameNumber
;
while
(
true
)
{
while
(
true
)
{
if
(!
in
.
readSegment
(
s
))
return
false
;
if
(!
in
.
readSegment
(
s
))
{
freeSegments
.
add
(
s
);
return
false
;
}
frameNumber
=
s
.
getSegmentNumber
()
/
n
;
frameNumber
=
s
.
getSegmentNumber
()
/
n
;
if
(
window
.
contains
(
frameNumber
))
break
;
if
(
window
.
contains
(
frameNumber
))
break
;
if
(
window
.
isTooHigh
(
frameNumber
))
countDiscard
(
frameNumber
);
if
(
window
.
isTooHigh
(
frameNumber
))
countDiscard
(
frameNumber
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment