Skip to content

Commit efafff8

Browse files
author
ARF
committed
__shapeIndex optimization: read into array and discard unneeded elements
x1.7 speedup over previous commit
1 parent 8f671db commit efafff8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

shapefile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ def __shapeIndex(self, i=None):
390390
# Jump to the first record.
391391
shx.seek(100)
392392
# Offsets are 16-bit words just like the file length
393-
self._offsets = [unpack('>i4x', shx.read(8))[0] * 2 for r in range(numRecords)]
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+
]
394398
if not i == None:
395399
return self._offsets[i]
396400

0 commit comments

Comments
 (0)