This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve implementation of rstrip and lstrip (JuliaLang#22496)
* change chomp! to chomp in readchomp `chomp` uses `SubString` so `chomp!` is not needed to ensure that copying of big string is not performed. * Remove chomp! function `chomp!` was only used in `readchomp` and I propose to replace it with `chomp` there. As `chomp!` was not exported I understand that it can be removed without deprecation. * Make rstrip and lstrip use SubString In this way copying of string is avoided, and in `strip` currently the string is actually copied twice. A basic benchmark is given below: ``` julia> using BenchmarkTools julia> s = " "^10*"x"^1000*" "^10; julia> @benchmark strip(s) # current definition BenchmarkTools.Trial: memory estimate: 2.13 KiB allocs estimate: 2 -------------- minimum time: 502.056 ns (0.00% GC) median time: 537.579 ns (0.00% GC) mean time: 631.383 ns (5.74% GC) maximum time: 6.003 μs (0.00% GC) -------------- samples: 10000 evals/sample: 197 julia> @benchmark strip(s) # with SubString definition BenchmarkTools.Trial: memory estimate: 64 bytes allocs estimate: 2 -------------- minimum time: 334.062 ns (0.00% GC) median time: 339.819 ns (0.00% GC) mean time: 362.150 ns (1.00% GC) maximum time: 8.236 μs (93.19% GC) -------------- samples: 10000 evals/sample: 243 ``` * Correct strip tests * Bring back chomp! * reverse removal of chomp! * Add NEWS entry for lstrip and rstrip. * remove trailing whitespace in NEWS.md
- Loading branch information