diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2026-08-12 19:45:38 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-12 11:45:38 +0000 |
| commit | f33c92348a77ae4cb62504b4cf71d1b7443bcf0e (patch) | |
| tree | 203bf9862c5be19c7e00bb6c938623e2f39bee08 /runtime/lua/vim/pack.lua | |
| parent | a0dc3f00675f738c6e69b71aa7c6e25a99bc4b6f (diff) | |
| download | rneovim-f33c92348a77ae4cb62504b4cf71d1b7443bcf0e.tar.gz rneovim-f33c92348a77ae4cb62504b4cf71d1b7443bcf0e.tar.bz2 rneovim-f33c92348a77ae4cb62504b4cf71d1b7443bcf0e.zip | |
vim-patch:9.2.0937: sort() with a numeric option converts each item on every comparison (#41286)
Problem: sort() with "n", "N" or "f" converts an item to its number on
every comparison. For "n" that is a tv2string() plus strtod()
per comparison, so sorting a list of numbers turns each number
into a string and back O(n log n) times, dwarfing the sort.
Solution: Compute the numeric key of each item once, before the sort,
and compare the stored key (Samuel Schlesinger). Only the
builtin numeric compare modes are affected; uniq(), which
passes a bare list item to the compare function, and the
string and user-function paths are unchanged.
Sorting a list of 100000 numbers (min of 3, macOS arm64):
- sort(l, 'n'): 0.205s -> 0.017s
- sort(l, 'N'): 0.017s -> 0.010s
- sort(l, 'f'): 0.014s -> 0.010s
The result is identical, including that a string is still treated as 0
in "n" mode and that "N" keeps full 64-bit precision.
Add Test_sort_numeric_precomputed(): a large shuffled list sorted with
"n", mixed integers and floats, int64 values beyond the exact range of
a double for "N", and uniq() over the non-precomputed path.
closes: vim/vim#21003
https://github.com/vim/vim/commit/c8c59db9dfdc2db5f17aa0a78ea1464f035bdf5e
Co-authored-by: Samuel Schlesinger <sgschlesinger@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to 'runtime/lua/vim/pack.lua')
0 files changed, 0 insertions, 0 deletions