Page MenuHomePhabricator

Python2/3 compatibility - ranges
ClosedPublic

Authored by serge-sans-paille on Dec 3 2018, 2:36 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

serge-sans-paille retitled this revision from Python2/3 compatibility to Python2/3 compatibility - ranges.Dec 3 2018, 2:51 AM
michaelplatings added inline comments.Dec 3 2018, 8:45 AM
bindings/python/clang/cindex.py
559 ↗(On Diff #176331)

This is unnecessary as xrange = range has already been declared above.

utils/ABITest/TypeGen.py
244 ↗(On Diff #176331)

Better to use the xrange = range trick from cindex.py

serge-sans-paille added a comment.EditedDec 3 2018, 9:24 AM

I failed to notice this trick, and I'd rather just use plain range. Overriding builtins is not a very good practice, and the performance drawback of using range instead of xrange in Python2 is negligible for such non-critical piece of software

In [1]: %timeit sum(range(1000))
100000 loops, best of 3: 7.72 µs per loop

In [2]: %timeit sum(xrange(1000))
100000 loops, best of 3: 6.56 µs per loop

xrange is the past, favor modern Python3 style :-)

This revision is now accepted and ready to land.Dec 13 2018, 2:34 AM
Closed by commit rL349448: Portable Python script across Python version (authored by serge_sans_paille, committed by ). · Explain WhyDec 18 2018, 12:27 AM
This revision was automatically updated to reflect the committed changes.