summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2016-05-02 22:31:20 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2016-05-02 23:01:46 -0700
commitd3a9c463353fb4dc2404a7eebdd676f9c56aae3d (patch)
tree6db4a4ba64000132c540a8dbb96ddc695e28d328
parent28faa60651745b0f6f04460cc90d71d84503fbb4 (diff)
downloadnatsort-d3a9c463353fb4dc2404a7eebdd676f9c56aae3d.tar.gz
Redefined _parse_string_function.
The new definition returns a function with no if statement in an attempt to micro-optimize this function.
-rw-r--r--natsort/utils.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/natsort/utils.py b/natsort/utils.py
index 527b3e0..a59036a 100644
--- a/natsort/utils.py
+++ b/natsort/utils.py
@@ -228,16 +228,24 @@ def _parse_number_function(alg, sep):
def _parse_string_function(alg, sep, splitter, pre, post, after):
"""Create a function that will properly split and format a string."""
- def func(x, not_dumb=not (alg & ns._DUMB and alg & ns.LOCALE)):
- original = x
- x = pre(x) # Apply pre-splitting function
- if not_dumb:
+ if not (alg & ns._DUMB and alg & ns.LOCALE):
+ def func(x):
+ x = pre(x) # Apply pre-splitting function
original = x
- x = splitter(x) # Split the string on numbers
- x = py23_filter(None, x) # Remove empty strings.
- x = py23_map(post, x) # Apply post-splitting function
- x = _sep_inserter(x, sep) # Insert empty strings between numbers
- return after(x, original) # Apply final manipulation
+ x = splitter(x) # Split the string on numbers
+ x = py23_filter(None, x) # Remove empty strings.
+ x = py23_map(post, x) # Apply post-splitting function
+ x = _sep_inserter(x, sep) # Insert empty strings between numbers
+ return after(x, original) # Apply final manipulation
+ else:
+ def func(x):
+ original = x
+ x = pre(x) # Apply pre-splitting function
+ x = splitter(x) # Split the string on numbers
+ x = py23_filter(None, x) # Remove empty strings.
+ x = py23_map(post, x) # Apply post-splitting function
+ x = _sep_inserter(x, sep) # Insert empty strings between numbers
+ return after(x, original) # Apply final manipulation
return func