Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
00a9b738
Commit
00a9b738
authored
Mar 29, 2009
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite IOBase.readall to avoid costly string resizes, and plug a leak
parent
7d037a7b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
38 deletions
+21
-38
Modules/_bufferedio.c
Modules/_bufferedio.c
+1
-10
Modules/_iobase.c
Modules/_iobase.c
+20
-28
No files found.
Modules/_bufferedio.c
View file @
00a9b738
...
...
@@ -1144,7 +1144,6 @@ _BufferedReader_read_unlocked(BufferedObject *self, Py_ssize_t n)
PyObject
*
data
,
*
res
=
NULL
;
Py_ssize_t
current_size
,
remaining
,
written
;
char
*
out
;
static
PyObject
*
sep
=
NULL
;
/* Special case for when the number of bytes to read is unspecified. */
if
(
n
==
-
1
)
{
...
...
@@ -1201,15 +1200,7 @@ _BufferedReader_read_unlocked(BufferedObject *self, Py_ssize_t n)
return
data
;
}
else
{
if
(
sep
==
NULL
)
{
sep
=
PyBytes_FromStringAndSize
(
NULL
,
0
);
if
(
sep
==
NULL
)
{
Py_DECREF
(
data
);
Py_DECREF
(
chunks
);
return
NULL
;
}
}
res
=
_PyBytes_Join
(
sep
,
chunks
);
res
=
_PyBytes_Join
(
_PyIO_empty_bytes
,
chunks
);
Py_DECREF
(
data
);
Py_DECREF
(
chunks
);
return
res
;
...
...
Modules/_iobase.c
View file @
00a9b738
...
...
@@ -809,49 +809,41 @@ PyDoc_STRVAR(RawIOBase_readall_doc,
static
PyObject
*
RawIOBase_readall
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
b
=
NULL
;
Py_ssize_t
cursize
=
0
;
int
r
;
PyObject
*
chunks
=
PyList_New
(
0
);
PyObject
*
result
;
if
(
chunks
==
NULL
)
return
NULL
;
while
(
1
)
{
Py_ssize_t
length
;
PyObject
*
data
=
PyObject_CallMethod
(
self
,
"read"
,
"i"
,
DEFAULT_BUFFER_SIZE
);
if
(
!
data
)
{
Py_
XDECREF
(
b
);
Py_
DECREF
(
chunks
);
return
NULL
;
}
if
(
!
PyBytes_Check
(
data
))
{
Py_
XDECREF
(
b
);
Py_
DECREF
(
chunks
);
Py_DECREF
(
data
);
PyErr_SetString
(
PyExc_TypeError
,
"read() should return bytes"
);
return
NULL
;
}
length
=
Py_SIZE
(
data
);
if
(
b
==
NULL
)
b
=
data
;
else
if
(
length
!=
0
)
{
_PyBytes_Resize
(
&
b
,
cursize
+
length
);
if
(
b
==
NULL
)
{
if
(
PyBytes_GET_SIZE
(
data
)
==
0
)
{
/* EOF */
Py_DECREF
(
data
);
return
NULL
;
break
;
}
memcpy
(
PyBytes_AS_STRING
(
b
)
+
cursize
,
PyBytes_AS_STRING
(
data
),
length
);
r
=
PyList_Append
(
chunks
,
data
);
Py_DECREF
(
data
);
if
(
r
<
0
)
{
Py_DECREF
(
chunks
);
return
NULL
;
}
if
(
length
==
0
)
break
;
}
return
b
;
result
=
_PyBytes_Join
(
_PyIO_empty_bytes
,
chunks
);
Py_DECREF
(
chunks
)
;
return
result
;
}
static
PyMethodDef
RawIOBase_methods
[]
=
{
...
...
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