Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: select rows programatically (#84)
* Add Row.Selected function This would allow to select rows programatically. See #79 for additional information. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Add test for selecting rows programatically This will fail, as the current implementation doesn't really work, however, this is useful to drive the right implementation. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Compute selected rows only when needed Previously the selected rows were cached in the model whenever the toggle mark key event was received. Moving that computation instead to the Model.SelectedRows function fixes this by only computing these rows when needed. I've also identified some optimizations that will be addressed in upcoming commits. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Add benchmark for Model.SelectedRows This will be useful for future optimizations. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Reduce allocations when computing selected rows By allocating the returned slice with an initial capacity but length 0 we reduce the number of allocations by roughly 80%. I've run the benchmark using the following command: go test ./table/ -bench=BenchmarkSelectedRows -benchtime=100000x -count=10 I've run the benchmark with the previous commit and with this one, and these are the results using benchstat for comparison: name old time/op new time/op delta SelectedRows-12 18.3µs ± 1% 17.0µs ± 1% -7.26% (p=0.000 n=8+10) name old alloc/op new alloc/op delta SelectedRows-12 84.2kB ± 0% 81.9kB ± 0% -2.70% (p=0.002 n=8+10) name old allocs/op new allocs/op delta SelectedRows-12 11.0 ± 0% 2.0 ± 0% -81.82% (p=0.000 n=10+10) As you can see there's also some small improvement in the overall performance of the call. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Remove unnecessary field in Model Given that the selected rows are now computed on the fly this field isn't needed anymore. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Update table/row.go Co-authored-by: Brandon Fulljames <bfullj@gmail.com> * Refactor Model.SelectedRows tests Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Add newline before return …and make the linter happy. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Revert "Reduce allocations when computing selected rows" This reverts commit 396041d. Co-authored-by: Brandon Fulljames <bfullj@gmail.com>
- Loading branch information