Skip to content

Commit 500fc85

Browse files
committed
Merge pull request #17 from felipou/master
minor performance tweak in python version
2 parents ae96b6c + e9f1b91 commit 500fc85

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

minify_json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
def json_minify(string, strip_space=True):
1818
tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r')
19+
end_slashes_re = re.compile(r'(\\)*$')
20+
1921
in_string = False
2022
in_multi = False
2123
in_single = False
@@ -36,7 +38,7 @@ def json_minify(string, strip_space=True):
3638
val = match.group()
3739

3840
if val == '"' and not (in_multi or in_single):
39-
escaped = re.search(r'(\\)*$', string[:match.start()])
41+
escaped = end_slashes_re.search(string, 0, match.start())
4042

4143
# start of string or unescaped quote character to end string
4244
if not in_string or (escaped is None or len(escaped.group()) % 2 == 0):

0 commit comments

Comments
 (0)