Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6263d545
Kaydet (Commit)
6263d545
authored
May 10, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rewrite readlines() to speed it up -- about a factor of 2 on my
Indigo2, reading a 9Meg file from the local disk.
üst
5449b6e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
25 deletions
+89
-25
fileobject.c
Objects/fileobject.c
+89
-25
No files found.
Objects/fileobject.c
Dosyayı görüntüle @
6263d545
...
...
@@ -451,25 +451,29 @@ file_read(f, args)
if
(
v
==
NULL
)
return
NULL
;
bytesread
=
0
;
Py_BEGIN_ALLOW_THREADS
for
(;;)
{
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
chunksize
=
fread
(
BUF
(
v
)
+
bytesread
,
1
,
buffersize
-
bytesread
,
f
->
f_fp
);
/* XXX Error check? */
if
(
chunksize
==
0
)
break
;
Py_END_ALLOW_THREADS
if
(
chunksize
==
0
)
{
if
(
!
ferror
(
f
->
f_fp
))
break
;
PyErr_SetFromErrno
(
PyExc_IOError
);
clearerr
(
f
->
f_fp
);
Py_DECREF
(
v
);
return
NULL
;
}
bytesread
+=
chunksize
;
if
(
bytesread
<
buffersize
)
break
;
if
(
bytesrequested
<
0
)
{
buffersize
=
new_buffersize
(
f
,
buffersize
);
Py_BLOCK_THREADS
if
(
_PyString_Resize
(
&
v
,
buffersize
)
<
0
)
return
NULL
;
Py_UNBLOCK_THREADS
}
}
Py_END_ALLOW_THREADS
if
(
bytesread
!=
buffersize
)
_PyString_Resize
(
&
v
,
bytesread
);
return
v
;
...
...
@@ -488,24 +492,21 @@ file_readinto(f, args)
if
(
!
PyArg_Parse
(
args
,
"w#"
,
&
ptr
,
&
ntodo
))
return
NULL
;
ndone
=
0
;
/*
** XXXX Is this correct? Other threads may see partially-completed
** reads if they look at the object we're reading into...
*/
Py_BEGIN_ALLOW_THREADS
while
(
ntodo
>
0
)
{
while
(
ntodo
>
0
)
{
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
nnow
=
fread
(
ptr
+
ndone
,
1
,
ntodo
,
f
->
f_fp
);
if
(
nnow
<
0
)
{
Py_END_ALLOW_THREADS
if
(
nnow
==
0
)
{
if
(
!
ferror
(
f
->
f_fp
))
break
;
PyErr_SetFromErrno
(
PyExc_IOError
);
clearerr
(
f
->
f_fp
);
return
NULL
;
}
if
(
nnow
==
0
)
break
;
ndone
+=
nnow
;
ntodo
-=
nnow
;
}
Py_END_ALLOW_THREADS
return
PyInt_FromLong
(
ndone
);
}
...
...
@@ -675,6 +676,14 @@ file_readlines(f, args)
{
PyObject
*
list
;
PyObject
*
line
;
char
small_buffer
[
SMALLCHUNK
];
char
*
buffer
=
small_buffer
;
size_t
buffersize
=
SMALLCHUNK
;
PyObject
*
big_buffer
=
NULL
;
size_t
nfilled
=
0
;
size_t
nread
;
char
*
p
,
*
q
,
*
end
;
int
err
;
if
(
f
->
f_fp
==
NULL
)
return
err_closed
();
...
...
@@ -683,18 +692,73 @@ file_readlines(f, args)
if
((
list
=
PyList_New
(
0
))
==
NULL
)
return
NULL
;
for
(;;)
{
line
=
getline
(
f
,
0
);
if
(
line
!=
NULL
&&
PyString_Size
(
line
)
==
0
)
{
Py_DECREF
(
line
);
break
;
}
if
(
line
==
NULL
||
PyList_Append
(
list
,
line
)
!=
0
)
{
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
nread
=
fread
(
buffer
+
nfilled
,
1
,
buffersize
-
nfilled
,
f
->
f_fp
);
Py_END_ALLOW_THREADS
if
(
nread
==
0
)
{
if
(
nread
==
0
)
break
;
PyErr_SetFromErrno
(
PyExc_IOError
);
clearerr
(
f
->
f_fp
);
error:
Py_DECREF
(
list
);
Py_XDECREF
(
line
)
;
return
NULL
;
list
=
NULL
;
goto
cleanup
;
}
p
=
memchr
(
buffer
+
nfilled
,
'\n'
,
nread
);
if
(
p
==
NULL
)
{
/* Need a larger buffer to fit this line */
nfilled
+=
nread
;
buffersize
*=
2
;
if
(
big_buffer
==
NULL
)
{
/* Create the big buffer */
big_buffer
=
PyString_FromStringAndSize
(
NULL
,
buffersize
);
if
(
big_buffer
==
NULL
)
goto
error
;
buffer
=
PyString_AS_STRING
(
big_buffer
);
memcpy
(
buffer
,
small_buffer
,
nfilled
);
}
else
{
/* Grow the big buffer */
_PyString_Resize
(
&
big_buffer
,
buffersize
);
buffer
=
PyString_AS_STRING
(
big_buffer
);
}
continue
;
}
end
=
buffer
+
nfilled
+
nread
;
q
=
buffer
;
do
{
/* Process complete lines */
p
++
;
line
=
PyString_FromStringAndSize
(
q
,
p
-
q
);
if
(
line
==
NULL
)
goto
error
;
err
=
PyList_Append
(
list
,
line
);
Py_DECREF
(
line
);
if
(
err
!=
0
)
goto
error
;
q
=
p
;
p
=
memchr
(
q
,
'\n'
,
end
-
q
);
}
while
(
p
!=
NULL
);
/* Move the remaining incomplete line to the start */
nfilled
=
end
-
q
;
memmove
(
buffer
,
q
,
nfilled
);
}
if
(
nfilled
!=
0
)
{
/* Partial last line */
line
=
PyString_FromStringAndSize
(
buffer
,
nfilled
);
if
(
line
==
NULL
)
goto
error
;
err
=
PyList_Append
(
list
,
line
);
Py_DECREF
(
line
);
if
(
err
!=
0
)
goto
error
;
}
cleanup
:
if
(
big_buffer
)
Py_DECREF
(
big_buffer
);
return
list
;
}
...
...
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