Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Mon, 21 Mar 2016 19:20:31 -0400 Organization: IISS Elusive Unicorn Lines: 64 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 0omT9TW9Y9y40NFh/eLKwwuaBbtnnJY/yWSevfxNn3bw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'granted,': 0.07; 'indexing': 0.07; 'global,': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:which': 0.09; 'python': 0.10; '(ie,': 0.16; '2016': 0.16; '8-bit': 0.16; 'later).': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'true:': 0.16; 'memory': 0.17; 'string': 0.17; 'url:home': 0.18; 'input': 0.18; 'language': 0.19; 'pass': 0.22; 'mon,': 0.24; 'header:X -Complaints-To:1': 0.26; 'rest': 0.26; 'least': 0.27; 'function': 0.28; 'idea': 0.28; 'looks': 0.29; 'if,': 0.29; 'invoke': 0.29; 'whitespace': 0.29; 'character': 0.29; 'table': 0.32; 'returned': 0.32; 'source': 0.33; 'skip:d 20': 0.34; 'something': 0.35; 'needed': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'why': 0.39; 'along': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'chance': 0.60; 'your': 0.60; 'subject:The': 0.61; 'suitable': 0.61; 'entire': 0.61; 'total': 0.62; 'back': 0.62; 'making': 0.62; 'sample': 0.63; 'between': 0.65; 'mar': 0.65; '257': 0.84; '>def': 0.84; 'are...': 0.84; 'dennis': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-79-219-206.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105414 On Mon, 21 Mar 2016 17:31:21 +0000, BartC declaimed the following: > >def readtoken(psource): > global lxsptr, lxsymbol Why is "lxsymbol" a global, and not something returned by the function (I can understand your making lxsptr global as you intend to come back in with it later). > lxsubcode = 0 > Unused in the rest of the sample > while (1): while True: #At least since Python 2.x... No () needed > c=psource[lxsptr] Is the spacebar broken? How about some whitespace between language elements... They don't take up that much memory > lxsptr+=1 > d=ord(c) Given that you state you expect to only be working with 8-bit bytes... > if d<256: this will always be true > lxsymbol = disptable[d](psource,c) Looks like you are indexing a 256-element table of functions, using the numeric value of the character/byte as the index... Only to then pass your entire source string along with the character from it to the function. > else: > lxsymbol = fn_error(psource,c) > > if lxsymbol != skip_sym: > break > I have no idea what your disptable functions look like but... while psource: c, psource = psource[0], psource[1:] lxsymbol = disptable[min(ord(c), 256)](c, psource) # if, by some chance ord(c) is >255, this will invoke a last-chance # catch function in disptable[256] (ie, 257 total entries) if lxsysmbol == skip_sym: continue return lxsysmbol, psource Note that this loop "consumes" the input string as it cycles, so no need to keep track of where in it we are... Granted, if you need to back track this may not be suitable -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/