cpython: 088a14031998 (original) (raw)
Mercurial > cpython
changeset 82225:088a14031998
Issue #8745: Small speed up zipimport on Windows. Patch by Catalin Iacob. [#8745]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 16 Feb 2013 17:43:45 +0200 |
parents | 73a16d3c066a |
children | aa17a0dab86a |
files | Lib/test/test_zipimport.py Misc/NEWS Modules/zipimport.c |
diffstat | 3 files changed, 22 insertions(+), 9 deletions(-)[+] [-] Lib/test/test_zipimport.py 2 Misc/NEWS 2 Modules/zipimport.c 27 |
line wrap: on
line diff
--- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -196,6 +196,7 @@ class UncompressedZipImportTestCase(Impo for name, (mtime, data) in files.items(): zinfo = ZipInfo(name, time.localtime(mtime)) zinfo.compress_type = self.compression
zinfo.comment = b"spam"[](#l1.7) z.writestr(zinfo, data)[](#l1.8) z.close()[](#l1.9)
@@ -245,6 +246,7 @@ class UncompressedZipImportTestCase(Impo for name, (mtime, data) in files.items(): zinfo = ZipInfo(name, time.localtime(mtime)) zinfo.compress_type = self.compression
zinfo.comment = b"eggs"[](#l1.15) z.writestr(zinfo, data)[](#l1.16) z.close()[](#l1.17)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #8745: Small speed up zipimport on Windows. Patch by Catalin Iacob. +
- Issue #5308: Raise ValueError when marshalling too large object (a sequence with size >= 2**31), instead of producing illegal marshal data.
--- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -862,6 +862,7 @@ read_directory(PyObject *archive) long l, count; Py_ssize_t i; char name[MAXPATHLEN + 5];
- char dummy[8]; /* Buffer to read unused header values into */ PyObject *nameobj = NULL; char p, endof_central_dir[22]; Py_ssize_t arc_offset; / Absolute offset to start of the zip-archive. */ @@ -905,17 +906,23 @@ read_directory(PyObject archive) / Start of Central Directory */ count = 0;
- if (fseek(fp, header_offset, 0) == -1)
for (;;) { PyObject *t; int err;goto file_error;[](#l3.16)
if (fseek(fp, header_offset, 0) == -1) /* Start of file header */[](#l3.21)
goto fseek_error;[](#l3.22)
/* Start of file header */[](#l3.23) l = PyMarshal_ReadLongFromFile(fp);[](#l3.24) if (l != 0x02014B50)[](#l3.25) break; /* Bad: Central Dir File Header */[](#l3.26)
if (fseek(fp, header_offset + 8, 0) == -1)[](#l3.27)
goto fseek_error;[](#l3.28)
/* On Windows, calling fseek to skip over the fields we don't use is[](#l3.30)
slower than reading the data into a dummy buffer because fseek flushes[](#l3.31)
stdio's internal buffers. See issue #8745. */[](#l3.32)
if (fread(dummy, 1, 4, fp) != 4) /* Skip unused fields, avoid fseek */[](#l3.33)
goto file_error;[](#l3.34)
+ flags = (unsigned short)PyMarshal_ReadShortFromFile(fp); compress = PyMarshal_ReadShortFromFile(fp); time = PyMarshal_ReadShortFromFile(fp); @@ -924,11 +931,11 @@ read_directory(PyObject *archive) data_size = PyMarshal_ReadLongFromFile(fp); file_size = PyMarshal_ReadLongFromFile(fp); name_size = PyMarshal_ReadShortFromFile(fp);
header_size = 46 + name_size +[](#l3.43)
header_size = name_size +[](#l3.44) PyMarshal_ReadShortFromFile(fp) +[](#l3.45) PyMarshal_ReadShortFromFile(fp);[](#l3.46)
if (fseek(fp, header_offset + 42, 0) == -1)[](#l3.47)
goto fseek_error;[](#l3.48)
if (fread(dummy, 1, 8, fp) != 8) /* Skip unused fields, avoid fseek */[](#l3.49)
goto file_error;[](#l3.50) file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset;[](#l3.51) if (name_size > MAXPATHLEN)[](#l3.52) name_size = MAXPATHLEN;[](#l3.53)
@@ -941,7 +948,9 @@ read_directory(PyObject *archive) p++; } p = 0; / Add terminating null byte */
header_offset += header_size;[](#l3.58)
for (; i < header_size; i++) /* Skip the rest of the header */[](#l3.59)
if(getc(fp) == EOF) /* Avoid fseek */[](#l3.60)
goto file_error;[](#l3.61)
bootstrap = 0; if (flags & 0x0800) @@ -988,7 +997,7 @@ read_directory(PyObject *archive) PySys_FormatStderr("# zipimport: found %ld names in %R\n", count, archive); return files; -fseek_error: +file_error: fclose(fp); Py_XDECREF(files); Py_XDECREF(nameobj);