fix: support natural ordering for numbers with >12 digits#652
fix: support natural ordering for numbers with >12 digits#652stevearc merged 3 commits intostevearc:masterfrom XeroOl:master
Conversation
Changes the column ordering code when `view_options.natural_order` is enabled, so that it can support larger numbers. The previous 12-digit padding approach breaks for numbers above 12 digits. This length-prefixed approach can scale to much higher numbers. I picked %03 (padding 3 digits) because most filesystems don't allow more than 255 bytes in a path segment, and "255" is 3 digits long.
|
With the original natural order PR you said you did benchmarking. I'm curious what the methodology was, because I want to know if I've improved performance at all |
|
Okay I've run the benchmark (with On my computer: So this PR does slow down the code. If this is a problem I would be happy to work on performance. |
|
Okay! I've fixed the performance! The main problem is that the sort key callback is being called many times repeatedly for each item. I added memoization so that the key only needs to be computed once per sort. (Also I swapped an Before this PR:
After PR:
|
|
Nice work! I appreciate the iteration on performance |
Changes the column ordering code when
view_options.natural_orderis enabled, so that it can support larger numbers.I chose to handle numbers of up to 999 digits, because some cursory research seems to suggest to me that most filesystems cap at 255 bytes per segment, and 999 > 255, so it should be sufficient for all actual filenames.
Performance may have changed but I don't know if it will be better or worse.
I've slightly increased the complexity of the
string.formatformat specifier, but the final strings will be shorter on average, andstring.formatno longer has to implicitly coerceintfrom a string into a number.before:


after: