|
|
|
|
|
by tom_mellior
3058 days ago
|
|
This is a bit misleading. You suggest that local variables are looked up by name in a dictionary, which is not the case. They are looked up by indexing into a C array, with the index being a constant in the bytecode. That's quite a lot simpler. Here is the corresponding code (look above for the definition of the GETLOCAL macro): https://github.com/python/cpython/blob/fc1ce810f1da593648b4d... So your code should be more like: locals[a_idx] = locals[foo_idx]->__getattribute__('bar')(locals[b_idx])
But this isn't a very good rendering of the thing because it doesn't show the many redundant reference count increment/decrement pairs every time you touch a variable.(Also, interpreter dispatch uses computed GOTOs instead of the plain switch on C compilers that support it.) |
|