Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
og-rek
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
og-rek
Commits
9627bcd9
Commit
9627bcd9
authored
Feb 16, 2017
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse buffer when decoding unicode characters
parent
60b23d0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
ogorek.go
ogorek.go
+13
-5
No files found.
ogorek.go
View file @
9627bcd9
...
...
@@ -107,12 +107,16 @@ type Decoder struct {
r
*
bufio
.
Reader
stack
[]
interface
{}
memo
map
[
string
]
interface
{}
// a reusable buffer that can be used by the various decoding functions
// functions using this should call buf.Reset to clear the old contents
buf
bytes
.
Buffer
}
// NewDecoder constructs a new Decoder which will decode the pickle stream in r.
func
NewDecoder
(
r
io
.
Reader
)
Decoder
{
reader
:=
bufio
.
NewReader
(
r
)
return
Decoder
{
r
eader
,
make
([]
interface
{},
0
),
make
(
map
[
string
]
interface
{})}
return
Decoder
{
r
:
reader
,
stack
:
make
([]
interface
{},
0
),
memo
:
make
(
map
[
string
]
interface
{})}
}
// Decode decodes the pickle stream and returns the result or an error.
...
...
@@ -487,6 +491,8 @@ func (d *Decoder) loadBinString() error {
return
err
}
v
:=
binary
.
LittleEndian
.
Uint32
(
b
[
:
])
// TODO: use d.buf to reduce allocations?
s
:=
make
([]
byte
,
v
)
_
,
err
=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
...
...
@@ -502,6 +508,7 @@ func (d *Decoder) loadShortBinString() error {
return
err
}
// TODO: use d.buf to reduce allocations?
s
:=
make
([]
byte
,
b
)
_
,
err
=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
...
...
@@ -519,13 +526,13 @@ func (d *Decoder) loadUnicode() error {
}
sline
:=
string
(
line
)
buf
:=
bytes
.
Buffer
{}
d
.
buf
.
Reset
()
for
len
(
sline
)
>
0
{
var
r
rune
var
err
error
for
len
(
sline
)
>
0
&&
sline
[
0
]
==
'\'
'
{
buf
.
WriteByte
(
sline
[
0
])
d
.
buf
.
WriteByte
(
sline
[
0
])
sline
=
sline
[
1
:
]
}
if
len
(
sline
)
==
0
{
...
...
@@ -535,13 +542,13 @@ func (d *Decoder) loadUnicode() error {
if
err
!=
nil
{
return
err
}
buf
.
WriteRune
(
r
)
d
.
buf
.
WriteRune
(
r
)
}
if
len
(
sline
)
>
0
{
return
fmt
.
Errorf
(
"characters remaining after loadUnicode operation: %s"
,
sline
)
}
d
.
push
(
buf
.
String
())
d
.
push
(
d
.
buf
.
String
())
return
nil
}
...
...
@@ -818,6 +825,7 @@ func (d *Decoder) loadShortBinUnicode() error {
return
err
}
// TODO: use d.buf to save allocations?
s
:=
make
([]
byte
,
b
)
_
,
err
=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
...
...
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