Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
7d881e45
Commit
7d881e45
authored
Feb 25, 2019
by
Marius van der Wijden
Committed by
Péter Szilágyi
Feb 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: added pooling of streams using sync (#19044)
Prevents reallocation, improves performance
parent
872370e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
decode.go
rlp/decode.go
+17
-4
No files found.
rlp/decode.go
View file @
7d881e45
...
...
@@ -26,6 +26,7 @@ import (
"math/big"
"reflect"
"strings"
"sync"
)
var
(
...
...
@@ -48,6 +49,10 @@ var (
errUintOverflow
=
errors
.
New
(
"rlp: uint overflow"
)
errNoPointer
=
errors
.
New
(
"rlp: interface given to Decode must be a pointer"
)
errDecodeIntoNil
=
errors
.
New
(
"rlp: pointer given to Decode must not be nil"
)
streamPool
=
sync
.
Pool
{
New
:
func
()
interface
{}
{
return
new
(
Stream
)
},
}
)
// Decoder is implemented by types that require custom RLP
...
...
@@ -126,17 +131,24 @@ type Decoder interface {
//
// NewStream(r, limit).Decode(val)
func
Decode
(
r
io
.
Reader
,
val
interface
{})
error
{
// TODO: this could use a Stream from a pool.
return
NewStream
(
r
,
0
)
.
Decode
(
val
)
stream
:=
streamPool
.
Get
()
.
(
*
Stream
)
defer
streamPool
.
Put
(
stream
)
stream
.
Reset
(
r
,
0
)
return
stream
.
Decode
(
val
)
}
// DecodeBytes parses RLP data from b into val.
// Please see the documentation of Decode for the decoding rules.
// The input must contain exactly one value and no trailing data.
func
DecodeBytes
(
b
[]
byte
,
val
interface
{})
error
{
// TODO: this could use a Stream from a pool.
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
NewStream
(
r
,
uint64
(
len
(
b
)))
.
Decode
(
val
);
err
!=
nil
{
stream
:=
streamPool
.
Get
()
.
(
*
Stream
)
defer
streamPool
.
Put
(
stream
)
stream
.
Reset
(
r
,
uint64
(
len
(
b
)))
if
err
:=
stream
.
Decode
(
val
);
err
!=
nil
{
return
err
}
if
r
.
Len
()
>
0
{
...
...
@@ -853,6 +865,7 @@ func (s *Stream) Reset(r io.Reader, inputLimit uint64) {
if
s
.
uintbuf
==
nil
{
s
.
uintbuf
=
make
([]
byte
,
8
)
}
s
.
byteval
=
0
}
// Kind returns the kind and size of the next value in the
...
...
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