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 @@ -85,6 +85,8 @@ class AttributeDict(dict):
85
85
"^[0-9A-Fa-f][^0-9A-Fa-f]$" : "^[0-9A-Fa-f][^0-9A-Fa-f]$" ,
86
86
}
87
87
88
+ _pat_compiled = {}
89
+
88
90
def viml_add (lst , item ):
89
91
lst .append (item )
90
92
@@ -100,14 +102,23 @@ def viml_empty(obj):
100
102
def viml_equalci (a , b ):
101
103
return a .lower () == b .lower ()
102
104
105
+ def _get_compiled_pat (reg , flags ):
106
+ key = (reg , flags )
107
+ try :
108
+ return _pat_compiled [key ]
109
+ except KeyError :
110
+ pat = re .compile (reg , flags )
111
+ _pat_compiled [key ] = pat
112
+ return pat
113
+
103
114
def viml_eqreg (s , reg ):
104
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
115
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
105
116
106
117
def viml_eqregh (s , reg ):
107
- return re . search ( pat_vim2py [ reg ], s )
118
+ return _get_compiled_pat ( reg , 0 ). search ( s )
108
119
109
120
def viml_eqregq (s , reg ):
110
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
121
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
111
122
112
123
def viml_escape (s , chars ):
113
124
r = ''
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ class AttributeDict(dict):
85
85
"^[0-9A-Fa-f][^0-9A-Fa-f]$" : "^[0-9A-Fa-f][^0-9A-Fa-f]$" ,
86
86
}
87
87
88
+ _pat_compiled = {}
89
+
88
90
def viml_add (lst , item ):
89
91
lst .append (item )
90
92
@@ -100,14 +102,23 @@ def viml_empty(obj):
100
102
def viml_equalci (a , b ):
101
103
return a .lower () == b .lower ()
102
104
105
+ def _get_compiled_pat (reg , flags ):
106
+ key = (reg , flags )
107
+ try :
108
+ return _pat_compiled [key ]
109
+ except KeyError :
110
+ pat = re .compile (pat_vim2py [reg ], flags )
111
+ _pat_compiled [key ] = pat
112
+ return pat
113
+
103
114
def viml_eqreg (s , reg ):
104
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
115
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
105
116
106
117
def viml_eqregh (s , reg ):
107
- return re . search ( pat_vim2py [ reg ], s )
118
+ return _get_compiled_pat ( reg , 0 ). search ( s )
108
119
109
120
def viml_eqregq (s , reg ):
110
- return re . search ( pat_vim2py [ reg ], s , re .IGNORECASE )
121
+ return _get_compiled_pat ( reg , re .IGNORECASE ). search ( s )
111
122
112
123
def viml_escape (s , chars ):
113
124
r = ''
You can’t perform that action at this time.
0 commit comments