The new optimization should not change the current Python SWITCH opcode and proceeding with the usual if-elif-else byte The standard if-elif-else processing by simply skipping the This condition is not met, the interpreter should revert to Use the hash table for finding the right opcode snippet. Well-known immutable types (strings, unicode, numbers) and Triggers the following run-time behaviour:Īt runtime, SWITCH would check x for being one of the Table, store it in the constants and add an opcode SWITCH inįront of the standard if-elif-else byte code stream which The compiler could then setup a read-only (perfect) hash Should be comparable to the type of the left hand switch Right hand sides need not be all of the same type, but they The right hand side a hashable immutable builtin type. the left hand side always references the same variable, If-elif-else construct which has the following signature: It should be possible for the compiler to detect an (hashable, comparable, a=b => hash(a)=hash(b)). Terms of requiring that both the switch variable and theĬonstants need to be compatible to the dictionary implementation Jump location, so they both share the same problem space in Involve some run-time overhead to assure that the switchingīoth solutions use a dictionary lookup to find the right Keywords to the language, while the second looks cleaner. The first solution has the benefit of not relying on adding new Adding new syntax to Python which mimics the C style.Generates special opcodes for it which use a read-only Which detects the above if-elif-else construct and Adding an optimization to the Python compiler and VM.This PEP proposes two different but not necessarily conflicting Prominent cases include XML SAX parsers and Internet protocol Pickle.py which is used to serialize Python objects. append ( data )Ī nice example of this is the state machine implemented in Has been to use long switch constructs of the following type:ĭef handle_data ( self, data ): self. Up to Python 2.5, the typical way of writing multi-value switches With respect to handling switching on a single variable having This PEP proposes strategies to enhance Python’s performance So this proposal has no chance of being accepted either. Solution 2: Adding a switch statement to PythonĪ similar PEP for Python 3000, PEP 3103, was already rejected,.Toggle light / dark / auto colour theme PEP 275 – Switching on Multiple Values Author : Marc-André Lemburg Status : Rejected Type : Standards Track Created : 1 Python-Version : 2.6 Post-History : PEP 275 – Switching on Multiple Values | Following system colour scheme Selected dark colour scheme Selected light colour scheme Python Enhancement Proposals
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |