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
5c7136ad
Unverified
Commit
5c7136ad
authored
Aug 23, 2023
by
Felix Lange
Committed by
GitHub
Aug 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: remove allocation of bytes.Reader in DecodeBytes (#27987)
parent
52219ced
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
decode.go
rlp/decode.go
+22
-2
No files found.
rlp/decode.go
View file @
5c7136ad
...
...
@@ -90,7 +90,7 @@ func Decode(r io.Reader, val interface{}) error {
// DecodeBytes parses RLP data from b into val. Please see package-level documentation for
// the decoding rules. The input must contain exactly one value and no trailing data.
func
DecodeBytes
(
b
[]
byte
,
val
interface
{})
error
{
r
:=
bytes
.
NewReader
(
b
)
r
:=
(
*
sliceReader
)(
&
b
)
stream
:=
streamPool
.
Get
()
.
(
*
Stream
)
defer
streamPool
.
Put
(
stream
)
...
...
@@ -99,7 +99,7 @@ func DecodeBytes(b []byte, val interface{}) error {
if
err
:=
stream
.
Decode
(
val
);
err
!=
nil
{
return
err
}
if
r
.
Len
(
)
>
0
{
if
len
(
b
)
>
0
{
return
ErrMoreThanOneValue
}
return
nil
...
...
@@ -1182,3 +1182,23 @@ func (s *Stream) listLimit() (inList bool, limit uint64) {
}
return
true
,
s
.
stack
[
len
(
s
.
stack
)
-
1
]
}
type
sliceReader
[]
byte
func
(
sr
*
sliceReader
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
if
len
(
*
sr
)
==
0
{
return
0
,
io
.
EOF
}
n
:=
copy
(
b
,
*
sr
)
*
sr
=
(
*
sr
)[
n
:
]
return
n
,
nil
}
func
(
sr
*
sliceReader
)
ReadByte
()
(
byte
,
error
)
{
if
len
(
*
sr
)
==
0
{
return
0
,
io
.
EOF
}
b
:=
(
*
sr
)[
0
]
*
sr
=
(
*
sr
)[
1
:
]
return
b
,
nil
}
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