Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
8c199588
Commit
8c199588
authored
Mar 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xbufio: put buf/pos to head of struct; avoid 1 temporaray
parent
675a9e86
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
35 deletions
+48
-35
t/neo/storage/fs1/xbufio.go
t/neo/storage/fs1/xbufio.go
+5
-6
t/neo/storage/fs1/xbufio_test.go
t/neo/storage/fs1/xbufio_test.go
+43
-29
No files found.
t/neo/storage/fs1/xbufio.go
View file @
8c199588
...
@@ -13,11 +13,11 @@ import (
...
@@ -13,11 +13,11 @@ import (
// SeqBufReader implements buffering for a io.ReaderAt optimized for sequential access
// SeqBufReader implements buffering for a io.ReaderAt optimized for sequential access
// XXX -> xbufio.SeqReader
// XXX -> xbufio.SeqReader
type
SeqBufReader
struct
{
type
SeqBufReader
struct
{
r
io
.
ReaderAt
// buffer for data at pos. cap(buf) - whole buffer capacity
// buffer for data at pos. cap(buf) - whole buffer capacity
pos
int64
buf
[]
byte
buf
[]
byte
pos
int64
r
io
.
ReaderAt
}
}
// TODO text about syscall / memcpy etc
// TODO text about syscall / memcpy etc
...
@@ -95,8 +95,7 @@ func (sb *SeqBufReader) ReadAt(p []byte, pos int64) (n int, err error) {
...
@@ -95,8 +95,7 @@ func (sb *SeqBufReader) ReadAt(p []byte, pos int64) (n int, err error) {
}
}
}
}
buf
:=
sb
.
buf
[
:
cap
(
sb
.
buf
)]
nn
,
err
:=
sb
.
r
.
ReadAt
(
sb
.
buf
[
:
cap
(
sb
.
buf
)],
xpos
)
nn
,
err
:=
sb
.
r
.
ReadAt
(
buf
,
xpos
)
// nothing read - just return the error
// nothing read - just return the error
if
nn
==
0
{
if
nn
==
0
{
...
@@ -105,7 +104,7 @@ func (sb *SeqBufReader) ReadAt(p []byte, pos int64) (n int, err error) {
...
@@ -105,7 +104,7 @@ func (sb *SeqBufReader) ReadAt(p []byte, pos int64) (n int, err error) {
// even if there was an error, but data partly read, we remember it in the buffer
// even if there was an error, but data partly read, we remember it in the buffer
sb
.
pos
=
xpos
sb
.
pos
=
xpos
sb
.
buf
=
buf
[
:
nn
]
sb
.
buf
=
sb
.
buf
[
:
nn
]
// here we know:
// here we know:
// - some data was read
// - some data was read
...
...
t/neo/storage/fs1/xbufio_test.go
View file @
8c199588
...
@@ -38,12 +38,9 @@ func (r *XReader) ReadAt(p []byte, pos int64) (n int, err error) {
...
@@ -38,12 +38,9 @@ func (r *XReader) ReadAt(p []byte, pos int64) (n int, err error) {
return
n
,
err
return
n
,
err
}
}
func
TestSeqBufReader
(
t
*
testing
.
T
)
{
r
:=
&
XReader
{}
rb
:=
NewSeqBufReaderSize
(
r
,
10
)
// with 10 it is easier to do/check math for a human
// read @pos/len -> rb.pos, len(rb.buf)
// read @pos/len -> rb.pos, len(rb.buf)
testv
:
=
[]
struct
{
pos
int64
;
Len
int
;
bufPos
int64
;
bufLen
int
}
{
var
xSeqBufTestv
=
[]
struct
{
pos
int64
;
Len
int
;
bufPos
int64
;
bufLen
int
}
{
{
40
,
5
,
40
,
10
},
// 1st access, forward by default
{
40
,
5
,
40
,
10
},
// 1st access, forward by default
{
45
,
7
,
50
,
10
},
// part taken from buf, part read next, forward
{
45
,
7
,
50
,
10
},
// part taken from buf, part read next, forward
{
52
,
5
,
50
,
10
},
// everything taken from buf
{
52
,
5
,
50
,
10
},
// everything taken from buf
...
@@ -68,9 +65,14 @@ func TestSeqBufReader(t *testing.T) {
...
@@ -68,9 +65,14 @@ func TestSeqBufReader(t *testing.T) {
{
254
,
5
,
250
,
6
},
// access overlapping EOF - EOF returned
{
254
,
5
,
250
,
6
},
// access overlapping EOF - EOF returned
{
256
,
1
,
250
,
6
},
// access past EOF -> EOF
{
256
,
1
,
250
,
6
},
// access past EOF -> EOF
{
257
,
1
,
250
,
6
},
// ----//----
{
257
,
1
,
250
,
6
},
// ----//----
}
}
func
TestSeqBufReader
(
t
*
testing
.
T
)
{
r
:=
&
XReader
{}
rb
:=
NewSeqBufReaderSize
(
r
,
10
)
// with 10 it is easier to do/check math for a human
for
_
,
tt
:=
range
t
estv
{
for
_
,
tt
:=
range
xSeqBufT
estv
{
pOk
:=
make
([]
byte
,
tt
.
Len
)
pOk
:=
make
([]
byte
,
tt
.
Len
)
pB
:=
make
([]
byte
,
tt
.
Len
)
pB
:=
make
([]
byte
,
tt
.
Len
)
...
@@ -91,3 +93,15 @@ func TestSeqBufReader(t *testing.T) {
...
@@ -91,3 +93,15 @@ func TestSeqBufReader(t *testing.T) {
}
}
}
}
}
}
func
BenchmarkSeqBufReader
(
b
*
testing
.
B
)
{
r
:=
&
XReader
{}
rb
:=
NewSeqBufReaderSize
(
r
,
10
)
// same as in TestSeqBufReader
buf
:=
make
([]
byte
,
128
/* > all .Len in xSeqBufTestv */
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
_
,
tt
:=
range
xSeqBufTestv
{
rb
.
ReadAt
(
buf
[
:
tt
.
Len
],
tt
.
pos
)
}
}
}
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