[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread miss-islington
miss-islington added the comment: New changeset 32f5392f64f004382e26a988b1145d2dc96c4978 by Miss Islington (bot) in branch '3.6': bpo-32940: IDLE: Simplify StringTranslatePseudoMapping in pyparse (GH-5862) https://github.com/python/cpython/commit/32f5392f64f004382e26a988b1145d2dc96c4978

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread miss-islington
miss-islington added the comment: New changeset 7e5763469e2fc9d08a3f6b6205f87f20a1bdd465 by Miss Islington (bot) in branch '3.7': bpo-32940: IDLE: Simplify StringTranslatePseudoMapping in pyparse (GH-5862) https://github.com/python/cpython/commit/7e5763469e2fc9d08a3f6b6205f87f20a1bdd465

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread miss-islington
Change by miss-islington : -- pull_requests: +5710 stage: needs patch -> patch review ___ Python tracker ___ ___ Python-bugs-list mai

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread miss-islington
Change by miss-islington : -- pull_requests: +5711 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mai

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: New changeset f0daa880a405c8de6743e44fa46006754aa145c9 by Terry Jan Reedy (Cheryl Sabella) in branch 'master': bpo-32940: IDLE: Simplify StringTranslatePseudoMapping in pyparse (GH-5862) https://github.com/python/cpython/commit/f0daa880a405c8de6743e44fa4600675

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: The mapping passed to str.translate must map ints representing codepoints to either either ints or strings. Translate can extract binary codepoints for the new string from either. Ints are slightly faster, so I am inclined not to switch. import timeit clas

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: Replacing an expression with a less clear equivalent expression makes no sense to me. Anyway, having __missing__ return 120 reduces the benchmark miss time from 1.2-1.3 to .93, making ParseMis always faster than ParseGet and reducing the penalty for non-asci

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-27 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Don't use ord('x'). Use just 'x' or b'x'[0]. -- ___ Python tracker ___ ___ Python-bugs-list mail

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-27 Thread Terry J. Reedy
Terry J. Reedy added the comment: I settled on the following to compare ParseMap implementations. from idlelib.pyparse import Parser import timeit class ParseGet(dict): def __getitem__(self, key): return self.get(key, ord('x')) class ParseMis(dict): def __missing__(self, key): return o

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-25 Thread Cheryl Sabella
Cheryl Sabella added the comment: A similar regular expression version was mentioned on issue21765 and I had run some tests on it yesterday to verify. On my system, it ran at a factor of 10x slower, so if the translate finished in 0.003, the regex took 0.03. This was consistent for me, rega

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-25 Thread Terry J. Reedy
Terry J. Reedy added the comment: To me, it is plausible but not slam-dunk obvious that preloading ascii to 'x' mappings will make ascii lookup faster. On #21765, where the pyparse special translation was a side-issue, Tal Einat claimed that the unpublished regex he tried was 100x slower. --

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For efficiency I suggest to initialize the mapping with dict.fromkeys(range(128), 'x') rather of an empty dict. It is also possible to use regular expressions: _trans = re.compile(r'''[^(){}\[]"'\\\n#]+''') code = _trans.sub('x', code) code = code.replace('

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-24 Thread Terry J. Reedy
Terry J. Reedy added the comment: I simplified ParseMap to a dict subclass with one override -- __getitem__ and then the tests. They run faster. I suspect translate is faster. -- stage: patch review -> needs patch ___ Python tracker

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-24 Thread Cheryl Sabella
Cheryl Sabella added the comment: New PR submitted. Really glad I worked on this today. I learned a lot of things that were new to me. :-) -- ___ Python tracker ___ ___

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-24 Thread Cheryl Sabella
Change by Cheryl Sabella : -- pull_requests: +5637 stage: needs patch -> patch review ___ Python tracker ___ ___ Python-bugs-list mai

[issue32940] IDLE: pyparse - simplify StringTranslatePseudoMapping

2018-02-24 Thread Terry J. Reedy
Terry J. Reedy added the comment: I forget about this defaultdict behavior: "this value is inserted in the dictionary for the key, and returned." Reason: when default_factory returns a mutable, d[key] must return the same possibly mutated object with each call. I agree that defaultdict is n