On Feb 18, 5:59 am, "Deron Meranda" <[EMAIL PROTECTED]> wrote: > Consider a much-simplified example of such an iteration where > sometimes you need to transform an item by some function, but most of > the time you don't: > > if some_rare_condition: > func = some_transform_function > else: > func = lambda x: x > for item in some_sequence: > item2 = func(item) > ..... # more stuff > > Now the "lambda x:x" acts suitably like an identity operator. But it > is very slow, when compared to using more complex-looking code: > > do_transform = some_rare_condition > for item in some_sequence: > if do_transform: > item2 = transform_function(item) > else: > item2 = item > ..... # more stuff > > What python needs is something like a built-in "operator.identity" > function, which acts like "lambda x:x", but which the byte compiler > could recognize and completely optimize away so there is no function > call overhead.
Unless I'm misunderstanding you, you seem to be proposing that the compiler should avoid generating the call to func2() if it has a certain value. How could that information possibly be available at compile time? -- David -- http://mail.python.org/mailman/listinfo/python-list