lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


A smart optimizer could recognize the following and optimize them to avoid the likely n-squared costs:

	select( '#', ... )
	select( i, ... ) -- to a context wanting only a specific number of values

Of course, the optimizer would also have to recognize that select hadn't changed from its default, so we're pretty clearly in the sort of optimization territory pursued by LuaJIT.

For the simple iteration case, the following would be useful:

	for i, v in ivalues( ... ) do
		-- code
	end

[ Note that the the fact that returning nil stops the iteration means we can't just have values( ... ). I view this as defect in the definition of the generic for loop since one could use returning nothing as the appropriate indicator. That would, however, probably break a lot of existing iterator functions. ]

ivalues could even be optimized for the zero and one value cases to stick the value into the state parameter and return an appropriate iterator function. Beyond that, however, one is at the mercy of the speed of the allocator and collector.

Mark