Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
5dfd7dd2
Commit
5dfd7dd2
authored
7 years ago
by
Gav Wood
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Bring back zero copy
parent
491a5bce
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/substrate/runtime-support/src/storage.rs
+31
-8
31 additions, 8 deletions
substrate/substrate/runtime-support/src/storage.rs
with
31 additions
and
8 deletions
substrate/substrate/runtime-support/src/storage.rs
+
31
−
8
View file @
5dfd7dd2
...
...
@@ -22,11 +22,30 @@ use codec::{Slicable, KeyedVec};
// TODO: consider using blake256 to avoid possible preimage attack.
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
struct
IncrementalInput
<
'a
>
{
key
:
&
'a
[
u8
],
pos
:
usize
,
}
impl
<
'a
>
Input
for
IncrementalInput
<
'a
>
{
fn
read
(
&
mut
self
,
into
:
&
mut
[
u8
])
->
usize
{
let
len
=
runtime_io
::
read_storage
(
self
.key
,
into
,
self
.pos
)
.unwrap_or
(
0
);
let
read
=
::
rstd
::
cmp
::
min
(
len
,
into
.len
());
self
.pos
+=
read
;
read
}
}
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
pub
fn
get
<
T
:
Slicable
+
Sized
>
(
key
:
&
[
u8
])
->
Option
<
T
>
{
let
maybe_raw
=
runtime_io
::
storage
(
&
twox_128
(
key
)[
..
]);
maybe_raw
.map
(|
raw
|
Slicable
::
decode
(
&
mut
&
raw
[
..
])
.expect
(
"storage should contain a decodable value if there is some entry"
))
let
key
=
twox_128
(
key
);
runtime_io
::
read_storage
(
&
key
[
..
],
&
mut
[
0
;
0
][
..
],
0
)
.map
(|
_
|
{
let
mut
input
=
IncrementalInput
{
key
:
&
key
[
..
],
pos
:
0
,
};
Slicable
::
decode
(
&
mut
input
)
}
}
/// Return the value of the item in storage under `key`, or the type's default if there is no
...
...
@@ -153,11 +172,15 @@ pub mod unhashed {
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
pub
fn
get
<
T
:
Slicable
+
Sized
>
(
key
:
&
[
u8
])
->
Option
<
T
>
{
let
maybe_raw
=
runtime_io
::
storage
(
key
);
maybe_raw
.map
(|
raw
|
Slicable
::
decode
(
&
mut
&
raw
[
..
])
.expect
(
"storage should contain a decodable value if there is some entry"
))
runtime_io
::
read_storage
(
key
,
&
mut
[
0
;
0
][
..
],
0
)
.map
(|
_
|
{
let
mut
input
=
IncrementalInput
{
key
,
pos
:
0
,
};
Slicable
::
decode
(
&
mut
input
)
}
}
/// Return the value of the item in storage under `key`, or the type's default if there is no
/// explicit entry.
pub
fn
get_or_default
<
T
:
Slicable
+
Sized
+
Default
>
(
key
:
&
[
u8
])
->
T
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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