diff --git a/NEWS.md b/NEWS.md index 797c2c9c5a1ce..cba2ae445b698 100644 --- a/NEWS.md +++ b/NEWS.md @@ -73,6 +73,7 @@ Standard library changes * `Base.@kwdef` can now be used for parametric structs, and for structs with supertypes ([#29316]). * `merge(::NamedTuple, ::NamedTuple...)` can now be used with more than 2 `NamedTuple`s ([#29259]). * `Future.copy!` has been moved to `Base` ([#29178]). + * New `ncodeunits(c::Char)` method as a fast equivalent to `ncodeunits(string(c))` ([#29153]). Compiler/Runtime improvements ----------------------------- diff --git a/base/char.jl b/base/char.jl index 43eb92f0470d1..3f9d60380212b 100644 --- a/base/char.jl +++ b/base/char.jl @@ -56,6 +56,10 @@ Char Return the number of code units required to encode a character as UTF-8. This is the number of bytes which will be printed if the character is written to an output stream, or `ncodeunits(string(c))` but computed efficiently. + +!!! compat "Julia 1.1" + This method requires at least Julia 1.1. In Julia 1.0 consider + using `ncodeunits(string(c))`. """ ncodeunits(c::Char) = write(devnull, c) # this is surprisingly efficient