[Python-ideas] string codes & substring equality
Masklinn
masklinn at masklinn.net
Wed Nov 27 16:26:43 CET 2013
On 2013-11-27, at 15:32 , spir <denis.spir at gmail.com> wrote:
> Coming back to python after a long time.
> My present project is about (yet another) top-down matching / parsing lib. There are 2 issues that, I guess, may be rather easily solved by simple string methods. The core point is that any scanning / parsing process ends up, a the lowest level, constantly comparing either single-char (rather single-code) substrings or constant (literal) substrings of the source string. This is the only operation which, when successful, actually advances in the source. Thus, it is certainly worth having it efficient, or at the minimum not having it needlessly inefficient. I suppose the same functionalities can be highly useful in various other use cases of text processing.
> Note again that I'm rediscovering Python (with some pleasure :-), thus may miss known solutions -- but I asked on the tutor mailing list.
>
> In both cases, I guess ordinary idiomatic Python code actually _creates_ a new string object, as a substring of length 1 or more, which is otherwise useless
Have you tried using memoryviews? (or buffers for older python compat’)
More information about the Python-ideas
mailing list