Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
132c42ff
Commit
132c42ff
authored
Dec 08, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bufio: use copy - significant speedup for writers
R=r
https://golang.org/cl/167047
parent
5a4a08fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
12 deletions
+6
-12
src/pkg/bufio/bufio.go
src/pkg/bufio/bufio.go
+6
-12
No files found.
src/pkg/bufio/bufio.go
View file @
132c42ff
...
@@ -38,12 +38,6 @@ func (b BufSizeError) String() string {
...
@@ -38,12 +38,6 @@ func (b BufSizeError) String() string {
return
"bufio: bad buffer size "
+
strconv
.
Itoa
(
int
(
b
))
return
"bufio: bad buffer size "
+
strconv
.
Itoa
(
int
(
b
))
}
}
func
copySlice
(
dst
[]
byte
,
src
[]
byte
)
{
for
i
:=
0
;
i
<
len
(
dst
);
i
++
{
dst
[
i
]
=
src
[
i
]
}
}
// Buffered input.
// Buffered input.
...
@@ -90,7 +84,7 @@ func NewReader(rd io.Reader) *Reader {
...
@@ -90,7 +84,7 @@ func NewReader(rd io.Reader) *Reader {
func
(
b
*
Reader
)
fill
()
{
func
(
b
*
Reader
)
fill
()
{
// Slide existing data to beginning.
// Slide existing data to beginning.
if
b
.
w
>
b
.
r
{
if
b
.
w
>
b
.
r
{
copy
Slice
(
b
.
buf
[
0
:
b
.
w
-
b
.
r
],
b
.
buf
[
b
.
r
:
b
.
w
]);
copy
(
b
.
buf
[
0
:
b
.
w
-
b
.
r
],
b
.
buf
[
b
.
r
:
b
.
w
]);
b
.
w
-=
b
.
r
;
b
.
w
-=
b
.
r
;
}
else
{
}
else
{
b
.
w
=
0
b
.
w
=
0
...
@@ -135,7 +129,7 @@ func (b *Reader) Read(p []byte) (nn int, err os.Error) {
...
@@ -135,7 +129,7 @@ func (b *Reader) Read(p []byte) (nn int, err os.Error) {
if
n
>
b
.
w
-
b
.
r
{
if
n
>
b
.
w
-
b
.
r
{
n
=
b
.
w
-
b
.
r
n
=
b
.
w
-
b
.
r
}
}
copy
Slice
(
p
[
0
:
n
],
b
.
buf
[
b
.
r
:
b
.
r
+
n
]);
copy
(
p
[
0
:
n
],
b
.
buf
[
b
.
r
:
b
.
r
+
n
]);
p
=
p
[
n
:
];
p
=
p
[
n
:
];
b
.
r
+=
n
;
b
.
r
+=
n
;
b
.
lastbyte
=
int
(
b
.
buf
[
b
.
r
-
1
]);
b
.
lastbyte
=
int
(
b
.
buf
[
b
.
r
-
1
]);
...
@@ -307,10 +301,10 @@ func (b *Reader) ReadBytes(delim byte) (line []byte, err os.Error) {
...
@@ -307,10 +301,10 @@ func (b *Reader) ReadBytes(delim byte) (line []byte, err os.Error) {
buf
:=
make
([]
byte
,
n
);
buf
:=
make
([]
byte
,
n
);
n
=
0
;
n
=
0
;
for
i
:=
0
;
i
<
nfull
;
i
++
{
for
i
:=
0
;
i
<
nfull
;
i
++
{
copy
Slice
(
buf
[
n
:
n
+
len
(
full
[
i
])],
full
[
i
]);
copy
(
buf
[
n
:
n
+
len
(
full
[
i
])],
full
[
i
]);
n
+=
len
(
full
[
i
]);
n
+=
len
(
full
[
i
]);
}
}
copy
Slice
(
buf
[
n
:
n
+
len
(
frag
)],
frag
);
copy
(
buf
[
n
:
n
+
len
(
frag
)],
frag
);
return
buf
,
err
;
return
buf
,
err
;
}
}
...
@@ -375,7 +369,7 @@ func (b *Writer) Flush() os.Error {
...
@@ -375,7 +369,7 @@ func (b *Writer) Flush() os.Error {
}
}
if
e
!=
nil
{
if
e
!=
nil
{
if
n
>
0
&&
n
<
b
.
n
{
if
n
>
0
&&
n
<
b
.
n
{
copy
Slice
(
b
.
buf
[
0
:
b
.
n
-
n
],
b
.
buf
[
n
:
b
.
n
])
copy
(
b
.
buf
[
0
:
b
.
n
-
n
],
b
.
buf
[
n
:
b
.
n
])
}
}
b
.
n
-=
n
;
b
.
n
-=
n
;
b
.
err
=
e
;
b
.
err
=
e
;
...
@@ -422,7 +416,7 @@ func (b *Writer) Write(p []byte) (nn int, err os.Error) {
...
@@ -422,7 +416,7 @@ func (b *Writer) Write(p []byte) (nn int, err os.Error) {
if
n
>
len
(
p
)
{
if
n
>
len
(
p
)
{
n
=
len
(
p
)
n
=
len
(
p
)
}
}
copy
Slice
(
b
.
buf
[
b
.
n
:
b
.
n
+
n
],
p
[
0
:
n
]);
copy
(
b
.
buf
[
b
.
n
:
b
.
n
+
n
],
p
[
0
:
n
]);
b
.
n
+=
n
;
b
.
n
+=
n
;
nn
+=
n
;
nn
+=
n
;
p
=
p
[
n
:
];
p
=
p
[
n
:
];
...
...
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