The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Chris Angelico rosuav at gmail.com
Wed Mar 23 20:15:42 EDT 2016


On Thu, Mar 24, 2016 at 11:12 AM, Random832 <random832 at fastmail.com> wrote:
> I guess the question is, what do you _actually_ need the tail string
> for? If you're using it in a loop, to pop further characters from (the
> scenario that would cause it to be copying the string over lots of
> times), wouldn't it make more sense to use a StringIO (or, in the real
> world where your C source code isn't a string, a file) and let that
> class take care of handing out characters when you ask for them?
>
> Like...
>
> fsource = StringIO(psource)
>
> while True:
>     c = fsource.read(1)
>     lxsymbol = disptable[min(ord(c), 256)](c, fsource)

Or... just grab an iterator off the string and call next() on it?

ChrisA



More information about the Python-list mailing list