Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'else:': 0.03; 'insert': 0.05; 'string.': 0.05; 'string': 0.09; 'ascii': 0.09; 'immutable': 0.09; 'insertion': 0.09; 'inserts': 0.09; 'typed': 0.09; 'python': 0.11; 'def': 0.12; 'editor,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'implies': 0.16; 'resize': 0.16; 'save(self):': 0.16; 'wrote:': 0.18; 'char': 0.24; 'sorry,': 0.24; 'string,': 0.24; 'text.': 0.24; "i've": 0.25; 'shown': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'waste': 0.30; 'message-id:@mail.gmail.com': 0.30; 'end,': 0.31; 'idea,': 0.31; 'purely': 0.31; 'class': 0.32; 'beginning': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'editor': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'method': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; 'bad': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'new': 0.61; "you're": 0.61; 'show': 0.63; 'real': 0.63; 'such': 0.63; 'soon': 0.63; 'more': 0.64; '30,': 0.65; 'charset:windows-1252': 0.65; 'jul': 0.74; 'special': 0.74; 'characters,': 0.84; 'inefficient': 0.91; 'system:': 0.91; 'this;': 0.91; 'technique': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Ynw7CGZeZwK8rAAhgWmRYI3TqOpt56z/pqSPcIn+yFU=; b=XHxTsGYZqIVdVULFwFR7TvmLAr/DQF9NfXxVXzI+Nhxk10omSr/9UUUdd62OfUlyYX mxSP59pcnohv5p+invRirBLaAHG1RVZ9q+okEX3dkm+X5pWHpAR6NjbUHXtEWLKf0wgk M+PffaJk306siuC/et0a+gLl72tPzitbHtzXeQd96R5cChqn5GVtUjT962/oCEuoMIN6 1HvJuPjp+GVHUpqu+pLVka7OjHccMsRCdcL5UzWNyACDoYsrscYk61Rj/7eXDVkTcHaU PMhCK43o6IRJmve0jGkYMwIsO2XxFWKvHto7TUtW23/mROB1g3/hIZdMGNwFeY3X8WfX jykg== MIME-Version: 1.0 X-Received: by 10.52.34.40 with SMTP id w8mr22844198vdi.7.1375195557994; Tue, 30 Jul 2013 07:45:57 -0700 (PDT) In-Reply-To: <43ce1b65-9d6d-47dd-b209-9a3bbafc0b8c@googlegroups.com> References: <571a6dfe-fd66-42cf-92fc-8b97cbe6e9e4@googlegroups.com> <51DFDE65.5040001@Gmail.com> <4f1067f6-bc99-42ad-9166-37fb228b90e8@googlegroups.com> <51f14395$0$29971$c3e8da3$5496439d@news.astraweb.com> <51f15e03$0$29971$c3e8da3$5496439d@news.astraweb.com> <8203e802-9dc5-44c5-9547-6e1947ee224b@googlegroups.com> <43ce1b65-9d6d-47dd-b209-9a3bbafc0b8c@googlegroups.com> Date: Tue, 30 Jul 2013 15:45:57 +0100 Subject: Re: RE Module Performance From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375195560 news.xs4all.nl 15888 [2001:888:2000:d::a6]:54692 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51563 On Tue, Jul 30, 2013 at 3:01 PM, wrote: > I am pretty sure that once you have typed your 127504 > ascii characters, you are very happy the buffer of your > editor does not waste time in reencoding the buffer as > soon as you enter an =80, the 125505th char. Sorry, I wanted > to say z instead of euro, just to show that backspacing the > last char and reentering a new char implies twice a reencoding. You're still thinking that the editor's buffer is a Python string. As I've shown earlier, this is a really bad idea, and that has nothing to do with FSR/PEP 393. An immutable string is *horribly* inefficient at this; if you want to keep concatenating onto a string, the recommended method is a list of strings that gets join()d at the end, and the same technique works well here. Here's a little demo class that could make the basis for such a system: class EditorBuffer: def __init__(self,fn): self.fn=3Dfn self.buffer=3D[open(fn).read()] def insert(self,pos,char): if pos=3D=3D0: # Special case: insertion at beginning of buffer if len(self.buffer[0])>1024: self.buffer.insert(0,char) else: self.buffer[0]=3Dchar+self.buffer[0] return for idx,part in enumerate(self.buffer): l=3Dlen(part) if pos>l: pos-=3Dl continue if pos1024: self.buffer[idx:idx+1]=3Dself.buffer[idx],char else: self.buffer[idx]+=3Dchar return raise ValueError("Cannot insert past end of buffer") def __str__(self): return ''.join(self.buffer) def save(self): open(fn,"w").write(str(self)) It guarantees that inserts will never need to resize more than 1KB of text. As a real basis for an editor, it still sucks, but it's purely to prove this one point. ChrisA