Skip to content

Commit 4c0b9b4

Browse files
author
ARF
committed
__shapeIndex optimization: explicit format string excluding unneeded elements
x1.5 speedup over previous commit Due to unexplained reasons, this seems to significantly speed up the apparently untouched read().
1 parent efafff8 commit 4c0b9b4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

shapefile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,10 @@ def __shapeIndex(self, i=None):
389389
numRecords = shxRecordLength // 8
390390
# Jump to the first record.
391391
shx.seek(100)
392+
shxRecords = array.array('i', unpack(">" + "i4x" * numRecords,
393+
shx.read((4+4) * numRecords)))
392394
# Offsets are 16-bit words just like the file length
393-
self._offsets = [2*el for el in
394-
array.array('i', unpack(">%si" % (numRecords*2),
395-
shx.read(4 * numRecords*2))
396-
)[::2]
397-
]
395+
self._offsets = [2*el for el in shxRecords]
398396
if not i == None:
399397
return self._offsets[i]
400398

0 commit comments

Comments
 (0)