Larry Hastings wrote: > When compiling a mutable type with an immutable equivalent, does Python > generate create-empty-object/insert-each-item bytecodes, or does it > create an immutable constant then cast it to the appropriate type?
Last time I looked, for lists and dicts it creates an empty object and adds items to it one at a time, and for tuples it pushes all the items onto the stack and then uses a special create-tuple bytecode. For frozenset constructors it could use a similar technique as for tuples. If set comprehensions were to produce frozen sets, something else would need to be done, such as creating it mutable initially and freezing it after construction, or having a special bytecode that's allowed to add an item to a frozenset. > p.s. or maybe the create-empty-object takes an optional parameter of > "and reserve this much space inside"? That wouldn't work for set comprehensions, since there's no way of telling ahead of time how many items it will contain. It mightn't help much anyway, given Python's proportional reallocation strategy. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | [EMAIL PROTECTED] +--------------------------------------+ _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com