good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
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
Downloads
Patches
Plain Diff
rlp: added pooling of streams using sync (#19044)
Prevents reallocation, improves performance
parent
872370e3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rlp/decode.go
+17
-4
17 additions, 4 deletions
rlp/decode.go
with
17 additions
and
4 deletions
rlp/decode.go
+
17
−
4
View file @
7d881e45
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"math/big"
"math/big"
"reflect"
"reflect"
"strings"
"strings"
"sync"
)
)
var
(
var
(
...
@@ -48,6 +49,10 @@ var (
...
@@ -48,6 +49,10 @@ var (
errUintOverflow
=
errors
.
New
(
"rlp: uint overflow"
)
errUintOverflow
=
errors
.
New
(
"rlp: uint overflow"
)
errNoPointer
=
errors
.
New
(
"rlp: interface given to Decode must be a pointer"
)
errNoPointer
=
errors
.
New
(
"rlp: interface given to Decode must be a pointer"
)
errDecodeIntoNil
=
errors
.
New
(
"rlp: pointer given to Decode must not be nil"
)
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
// Decoder is implemented by types that require custom RLP
...
@@ -126,17 +131,24 @@ type Decoder interface {
...
@@ -126,17 +131,24 @@ type Decoder interface {
//
//
// NewStream(r, limit).Decode(val)
// NewStream(r, limit).Decode(val)
func
Decode
(
r
io
.
Reader
,
val
interface
{})
error
{
func
Decode
(
r
io
.
Reader
,
val
interface
{})
error
{
// TODO: this could use a Stream from a pool.
stream
:=
streamPool
.
Get
()
.
(
*
Stream
)
return
NewStream
(
r
,
0
)
.
Decode
(
val
)
defer
streamPool
.
Put
(
stream
)
stream
.
Reset
(
r
,
0
)
return
stream
.
Decode
(
val
)
}
}
// DecodeBytes parses RLP data from b into val.
// DecodeBytes parses RLP data from b into val.
// Please see the documentation of Decode for the decoding rules.
// Please see the documentation of Decode for the decoding rules.
// The input must contain exactly one value and no trailing data.
// The input must contain exactly one value and no trailing data.
func
DecodeBytes
(
b
[]
byte
,
val
interface
{})
error
{
func
DecodeBytes
(
b
[]
byte
,
val
interface
{})
error
{
// TODO: this could use a Stream from a pool.
r
:=
bytes
.
NewReader
(
b
)
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
return
err
}
}
if
r
.
Len
()
>
0
{
if
r
.
Len
()
>
0
{
...
@@ -853,6 +865,7 @@ func (s *Stream) Reset(r io.Reader, inputLimit uint64) {
...
@@ -853,6 +865,7 @@ func (s *Stream) Reset(r io.Reader, inputLimit uint64) {
if
s
.
uintbuf
==
nil
{
if
s
.
uintbuf
==
nil
{
s
.
uintbuf
=
make
([]
byte
,
8
)
s
.
uintbuf
=
make
([]
byte
,
8
)
}
}
s
.
byteval
=
0
}
}
// Kind returns the kind and size of the next value in the
// Kind returns the kind and size of the next value in the
...
...
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