Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bytes-sgx
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Markus Becker
bytes-sgx
Commits
b44fc314
You need to sign in or sign up before continuing.
Commit
b44fc314
authored
8 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Move Inner constructions to struct fns
parent
d0142aa6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bytes.rs
+64
-44
64 additions, 44 deletions
src/bytes.rs
with
64 additions
and
44 deletions
src/bytes.rs
+
64
−
44
View file @
b44fc314
...
...
@@ -365,12 +365,7 @@ impl Bytes {
pub
fn
new
()
->
Bytes
{
Bytes
{
inner
:
Inner2
{
inner
:
Inner
{
arc
:
AtomicPtr
::
new
(
ptr
::
null_mut
()),
ptr
:
ptr
::
null_mut
(),
len
:
0
,
cap
:
0
,
}
inner
:
Inner
::
empty
(),
}
}
}
...
...
@@ -390,19 +385,9 @@ impl Bytes {
/// ```
#[inline]
pub
fn
from_static
(
bytes
:
&
'static
[
u8
])
->
Bytes
{
let
ptr
=
bytes
.as_ptr
()
as
*
mut
u8
;
Bytes
{
inner
:
Inner2
{
inner
:
Inner
{
// `arc` won't ever store a pointer. Instead, use it to
// track the fact that the `Bytes` handle is backed by a
// static buffer.
arc
:
AtomicPtr
::
new
(
KIND_STATIC
as
*
mut
Shared
),
ptr
:
ptr
,
len
:
bytes
.len
(),
cap
:
bytes
.len
(),
}
inner
:
Inner
::
from_static
(
bytes
),
}
}
}
...
...
@@ -784,20 +769,10 @@ impl BytesMut {
/// ```
#[inline]
pub
fn
with_capacity
(
capacity
:
usize
)
->
BytesMut
{
if
capacity
<=
INLINE_CAP
{
unsafe
{
// Using uninitialized memory is ~30% faster
BytesMut
{
inner
:
Inner2
{
inner
:
Inner
{
arc
:
AtomicPtr
::
new
(
KIND_INLINE
as
*
mut
Shared
),
..
mem
::
uninitialized
()
},
},
}
}
}
else
{
BytesMut
::
from
(
Vec
::
with_capacity
(
capacity
))
BytesMut
{
inner
:
Inner2
{
inner
:
Inner
::
with_capacity
(
capacity
),
},
}
}
...
...
@@ -1186,21 +1161,10 @@ impl ops::DerefMut for BytesMut {
}
impl
From
<
Vec
<
u8
>>
for
BytesMut
{
fn
from
(
mut
src
:
Vec
<
u8
>
)
->
BytesMut
{
let
len
=
src
.len
();
let
cap
=
src
.capacity
();
let
ptr
=
src
.as_mut_ptr
();
mem
::
forget
(
src
);
fn
from
(
src
:
Vec
<
u8
>
)
->
BytesMut
{
BytesMut
{
inner
:
Inner2
{
inner
:
Inner
{
arc
:
AtomicPtr
::
new
(
ptr
::
null_mut
()),
ptr
:
ptr
,
len
:
len
,
cap
:
cap
,
}
inner
:
Inner
::
from_vec
(
src
),
},
}
}
...
...
@@ -1335,6 +1299,62 @@ impl<'a> IntoIterator for &'a BytesMut {
*/
impl
Inner
{
#[inline]
fn
empty
()
->
Inner
{
Inner
{
arc
:
AtomicPtr
::
new
(
ptr
::
null_mut
()),
ptr
:
ptr
::
null_mut
(),
len
:
0
,
cap
:
0
,
}
}
#[inline]
fn
from_static
(
bytes
:
&
'static
[
u8
])
->
Inner
{
let
ptr
=
bytes
.as_ptr
()
as
*
mut
u8
;
Inner
{
// `arc` won't ever store a pointer. Instead, use it to
// track the fact that the `Bytes` handle is backed by a
// static buffer.
arc
:
AtomicPtr
::
new
(
KIND_STATIC
as
*
mut
Shared
),
ptr
:
ptr
,
len
:
bytes
.len
(),
cap
:
bytes
.len
(),
}
}
#[inline]
fn
from_vec
(
mut
src
:
Vec
<
u8
>
)
->
Inner
{
let
len
=
src
.len
();
let
cap
=
src
.capacity
();
let
ptr
=
src
.as_mut_ptr
();
mem
::
forget
(
src
);
Inner
{
arc
:
AtomicPtr
::
new
(
ptr
::
null_mut
()),
ptr
:
ptr
,
len
:
len
,
cap
:
cap
,
}
}
#[inline]
fn
with_capacity
(
capacity
:
usize
)
->
Inner
{
if
capacity
<=
INLINE_CAP
{
unsafe
{
// Using uninitialized memory is ~30% faster
Inner
{
arc
:
AtomicPtr
::
new
(
KIND_INLINE
as
*
mut
Shared
),
..
mem
::
uninitialized
()
}
}
}
else
{
Inner
::
from_vec
(
Vec
::
with_capacity
(
capacity
))
}
}
/// Return a slice for the handle's view into the shared buffer
#[inline]
fn
as_ref
(
&
self
)
->
&
[
u8
]
{
...
...
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