Skip to content

Commit

Permalink
re.sub can be expensive when ran thousands of time
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnes committed Apr 18, 2023
1 parent e979b39 commit 14313c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mongo_thingy/camelcase.py
Expand Up @@ -7,13 +7,13 @@


def camelize(string):
if string.startswith("__"):
if string.startswith("__") or "_" not in string:
return string
return re.sub(CAMELIZE_RE, lambda m: m.group(1).upper(), string)


def uncamelize(string):
if string.startswith("__"):
if string.startswith("__") or "_" in string:
return string
return re.sub(UNCAMELIZE_RE, r"_\g<0>", string).lower()

Expand Down

0 comments on commit 14313c2

Please sign in to comment.