Skip to content

Commit

Permalink
News and compat annotation for #29153 (ncodeunits(::Char)).
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 1, 2018
1 parent 2206bf5 commit 4e67301
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -71,6 +71,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
-----------------------------
Expand Down
4 changes: 4 additions & 0 deletions base/char.jl
Expand Up @@ -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

Expand Down

0 comments on commit 4e67301

Please sign in to comment.