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
41b722de
Commit
41b722de
authored
8 years ago
by
Carl Lerche
Browse files
Options
Downloads
Patches
Plain Diff
Allow checking out AppendBufs from Pool
parent
d650404b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/alloc/pool.rs
+6
-1
6 additions, 1 deletion
src/alloc/pool.rs
test/test_append.rs
+31
-0
31 additions, 0 deletions
test/test_append.rs
with
37 additions
and
1 deletion
src/alloc/pool.rs
+
6
−
1
View file @
41b722de
use
super
::{
Mem
,
MemRef
};
use
super
::{
Mem
,
MemRef
};
use
buf
::{
ByteBuf
,
MutByteBuf
};
use
buf
::{
AppendBuf
,
ByteBuf
,
MutByteBuf
};
use
stable_heap
as
heap
;
use
stable_heap
as
heap
;
use
std
::{
mem
,
ptr
,
isize
,
usize
};
use
std
::{
mem
,
ptr
,
isize
,
usize
};
use
std
::
cell
::{
Cell
,
UnsafeCell
};
use
std
::
cell
::{
Cell
,
UnsafeCell
};
...
@@ -92,6 +92,11 @@ impl Pool {
...
@@ -92,6 +92,11 @@ impl Pool {
})
})
}
}
pub
fn
new_append_buf
(
&
self
)
->
Option
<
AppendBuf
>
{
let
len
=
self
.inner.buf_len
as
u32
;
self
.checkout
()
.map
(|
mem
|
unsafe
{
AppendBuf
::
from_mem_ref
(
mem
,
len
,
0
)
})
}
fn
checkout
(
&
self
)
->
Option
<
MemRef
>
{
fn
checkout
(
&
self
)
->
Option
<
MemRef
>
{
unsafe
{
unsafe
{
let
mut
ptr
=
self
.inner.next
.load
(
Ordering
::
Acquire
);
let
mut
ptr
=
self
.inner.next
.load
(
Ordering
::
Acquire
);
...
...
This diff is collapsed.
Click to expand it.
test/test_append.rs
+
31
−
0
View file @
41b722de
use
bytes
::{
ByteStr
,
Buf
,
MutBuf
};
use
bytes
::{
ByteStr
,
Buf
,
MutBuf
};
use
bytes
::
alloc
::
Pool
;
use
bytes
::
buf
::
AppendBuf
;
use
bytes
::
buf
::
AppendBuf
;
#[test]
#[test]
...
@@ -28,3 +29,33 @@ pub fn test_initial_buf_empty() {
...
@@ -28,3 +29,33 @@ pub fn test_initial_buf_empty() {
assert_eq!
(
dst
,
b"hello world"
);
assert_eq!
(
dst
,
b"hello world"
);
}
}
}
}
#[test]
pub
fn
test_append_buf_from_pool
()
{
let
pool
=
Pool
::
with_capacity
(
2
,
256
);
// Run in a loop a bunch in hope that if there is a memory issue, it will
// be exposed
for
_
in
0
..
1000
{
let
mut
buf
=
pool
.new_append_buf
()
.unwrap
();
let
mut
dst
:
Vec
<
u8
>
=
vec!
[];
assert_eq!
(
buf
.remaining
(),
256
);
buf
.write_slice
(
b"hello world"
);
assert_eq!
(
buf
.remaining
(),
245
);
assert_eq!
(
buf
.bytes
(),
b"hello world"
);
let
view1
=
buf
.slice
(
0
,
11
);
view1
.buf
()
.copy_to
(
&
mut
dst
)
.unwrap
();
assert_eq!
(
dst
,
b"hello world"
);
assert_eq!
(
view1
,
buf
.slice
(
0
,
11
));
drop
(
buf
);
let
mut
buf
=
pool
.new_append_buf
()
.unwrap
();
buf
.write_slice
(
b"zomg no no no no"
);
assert_eq!
(
dst
,
b"hello world"
);
}
}
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