mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-91524: Speed up the regular expression substitution (#91525)
Functions re.sub() and re.subn() and corresponding re.Pattern methods are now 2-3 times faster for replacement strings containing group references. Closes #91524 Primarily authored by serhiy-storchaka Serhiy Storchaka Minor-cleanups-by: Gregory P. Smith [Google] <greg@krypto.org>
This commit is contained in:
parent
176b6c57be
commit
75a6fadf36
9 changed files with 358 additions and 91 deletions
|
@ -52,6 +52,17 @@ typedef struct {
|
|||
Py_ssize_t mark[1];
|
||||
} MatchObject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
Py_ssize_t chunks; /* the number of group references and non-NULL literals
|
||||
* self->chunks <= 2*Py_SIZE(self) + 1 */
|
||||
PyObject *literal;
|
||||
struct {
|
||||
Py_ssize_t index;
|
||||
PyObject *literal; /* NULL if empty */
|
||||
} items[0];
|
||||
} TemplateObject;
|
||||
|
||||
typedef struct SRE_REPEAT_T {
|
||||
Py_ssize_t count;
|
||||
const SRE_CODE* pattern; /* points to REPEAT operator arguments */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue