timmerk / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

Accept xrange-like parameters as well as iterables. #93

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Some methods that accept iterables end up spending a lot of time
range-checking elements. This isn't really needed, as often the iterable is
an xrange or range object, and the whole range checking could be done once.

Suggest that range-like parameters be accepted so that quicker checks could
be performed.

For example:

s.allset(xrange(s.len)) -> s.allset(0, s.len)

s.set(xrange(100, 0, -5)) -> s.set(100, 0, -5)

Points to note:

1) Can't replace xrange(n) with just 'n'. Would need to say (0, n).
2) Could be confusion between ([a, b, c]) and (a, b, c).

Original issue reported on code.google.com by dr.scott...@gmail.com on 31 May 2010 at 8:46

GoogleCodeExporter commented 9 years ago
Perhaps a better alternative would be:

s.set(slice(a, b, c))

This avoids the nasty variable number of arguments, and the confusion with 
s.set((a,
b, c)).

Original comment by dr.scott...@gmail.com on 1 Jun 2010 at 4:13