aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-05-17 14:17:25 -0500
committerGitHub <noreply@github.com>2024-05-17 14:17:25 -0500
commit4c0d18c19773327dcd771d1da7805690e3e41255 (patch)
treee5e1bcdee576ed4a2044c1a7719f878b00f0fac4 /runtime/doc
parentaec4938a21a02d279d13a9eb64ef3b7cc592c374 (diff)
downloadrneovim-4c0d18c19773327dcd771d1da7805690e3e41255.tar.gz
rneovim-4c0d18c19773327dcd771d1da7805690e3e41255.tar.bz2
rneovim-4c0d18c19773327dcd771d1da7805690e3e41255.zip
fix(vim.iter): enable optimizations for arrays (lists with holes) (#28781)
The optimizations that vim.iter uses for array-like tables don't require that the source table has no holes. The only thing that needs to change is the determination if a table is "list-like": rather than requiring consecutive, integer keys, we can simply test for (positive) integer keys only, and remove any holes in the original array when we make a copy for the iterator.
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/lua.txt9
1 files changed, 5 insertions, 4 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 0be3c24b0a..fccda177d2 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -3830,6 +3830,7 @@ chained to create iterator "pipelines": the output of each pipeline stage is
input to the next stage. The first stage depends on the type passed to
`vim.iter()`:
• List tables (arrays, |lua-list|) yield only the value of each element.
+ • Holes (nil values) are allowed.
• Use |Iter:enumerate()| to also pass the index to the next stage.
• Or initialize with ipairs(): `vim.iter(ipairs(…))`.
• Non-list tables (|lua-dict|) yield both the key and value of each element.
@@ -4287,9 +4288,9 @@ Iter:totable() *Iter:totable()*
Collect the iterator into a table.
The resulting table depends on the initial source in the iterator
- pipeline. List-like tables and function iterators will be collected into a
- list-like table. If multiple values are returned from the final stage in
- the iterator pipeline, each value will be included in a table.
+ pipeline. Array-like tables and function iterators will be collected into
+ an array-like table. If multiple values are returned from the final stage
+ in the iterator pipeline, each value will be included in a table.
Examples: >lua
vim.iter(string.gmatch('100 20 50', '%d+')):map(tonumber):totable()
@@ -4302,7 +4303,7 @@ Iter:totable() *Iter:totable()*
-- { { 'a', 1 }, { 'c', 3 } }
<
- The generated table is a list-like table with consecutive, numeric
+ The generated table is an array-like table with consecutive, numeric
indices. To create a map-like table with arbitrary keys, use
|Iter:fold()|.