+= overloading?

Michael Hudson mwh at python.net
Mon Jun 18 15:04:48 EDT 2001


"Neil Macneale" <mac4-devnull at theory.org> writes:

> I am using a list as the data holding element, then appending to it in
> the __iadd__ function. Then I use ''.join(list) to make a string
> when the __str__ function is called.  I am doing this to minimize the
> number of string objects created,  and figure that append runs in
> constant time.  Is join optomized though?

Yes.  Well, fairly.

> It would defeat the purpose if join worked by creating a new string
> to join the first two, then added the third, etc.  I am assumming
> that join is implemented in C, and runs in 0(n) time, where n is the
> number of total characters.  Am I assuming incorrectly?

No, you've got it about right.

> I looked at string.py's join function, but that just called another
> join method, and I don't know where that one is implemented.

You should be looking in Objects/stringobject.c, the function called
"string_join".  It's significantly easier to read (and less buggy) in
2.1 than 2.0, and a little faster.

Cheers,
M.

-- 
  It's a measure of how much I love Python that I moved to VA, where
  if things don't work out Guido will buy a plantation and put us to
  work harvesting peanuts instead.     -- Tim Peters, comp.lang.python



More information about the Python-list mailing list