File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -142,12 +142,21 @@ def _split_pairs(p: Iterable[str]):
142
142
143
143
144
144
def _camel_to_snake (w ):
145
- if (c := _camel_to_snake .pattern .findall (w )):
146
- return '_' .join (map (str .lower , c ))
147
- return w
148
-
149
-
150
- _camel_to_snake .pattern = re .compile (r'[A-Z][a-z]*' )
145
+ try :
146
+ cache = _camel_to_snake .cache
147
+ if w in cache :
148
+ return cache [w ]
149
+ p = _camel_to_snake .pattern
150
+ except AttributeError :
151
+ p = _camel_to_snake .pattern = re .compile (r'[A-Z][a-z0-9]*' )
152
+ cache = _camel_to_snake .cache = {}
153
+ if (words := p .findall (w )):
154
+ res = '_' .join (map (str .lower , words ))
155
+ cache [w ] = res
156
+ return res
157
+ else :
158
+ cache [w ] = w
159
+ return w
151
160
152
161
153
162
@functools .lru_cache (maxsize = 128 , typed = True )
You can’t perform that action at this time.
0 commit comments