File tree 2 files changed +28
-6
lines changed
2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ class AttributeDict(dict):
82
82
"^[0-7]$" : "^[0-7]$" ,
83
83
}
84
84
85
+ _pat_compiled = {}
86
+
85
87
def viml_add (lst , item ):
86
88
lst .append (item )
87
89
@@ -97,14 +99,23 @@ def viml_empty(obj):
97
99
def viml_equalci (a , b ):
98
100
return a .lower () == b .lower ()
99
101
102
+ def _get_compiled_pat (reg , flags ):
103
+ key = (reg , flags )
104
+ try :
105
+ return _pat_compiled [key ]
106
+ except KeyError :
107
+ pat = re .compile (reg , flags )
108
+ _pat_compiled [key ] = pat
109
+ return pat
110
+
100
111
def viml_eqreg (s , reg ):
101
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
112
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
102
113
103
114
def viml_eqregh (s , reg ):
104
- return re . search ( pat_vim2py [ reg ], s )
115
+ return _get_compiled_pat ( reg , 0 ). search ( s )
105
116
106
117
def viml_eqregq (s , reg ):
107
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
118
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
108
119
109
120
def viml_escape (s , chars ):
110
121
r = ''
Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ class AttributeDict(dict):
82
82
"^[0-7]$" : "^[0-7]$" ,
83
83
}
84
84
85
+ _pat_compiled = {}
86
+
85
87
def viml_add (lst , item ):
86
88
lst .append (item )
87
89
@@ -97,14 +99,23 @@ def viml_empty(obj):
97
99
def viml_equalci (a , b ):
98
100
return a .lower () == b .lower ()
99
101
102
+ def _get_compiled_pat (reg , flags ):
103
+ key = (reg , flags )
104
+ try :
105
+ return _pat_compiled [key ]
106
+ except KeyError :
107
+ pat = re .compile (pat_vim2py [reg ], flags )
108
+ _pat_compiled [key ] = pat
109
+ return pat
110
+
100
111
def viml_eqreg (s , reg ):
101
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
112
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
102
113
103
114
def viml_eqregh (s , reg ):
104
- return re . search ( pat_vim2py [ reg ], s )
115
+ return _get_compiled_pat ( reg , 0 ). search ( s )
105
116
106
117
def viml_eqregq (s , reg ):
107
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
118
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
108
119
109
120
def viml_escape (s , chars ):
110
121
r = ''
You can’t perform that action at this time.
0 commit comments