Skip to content

Commit 05ff71f

Browse files
stevengjJeffBezanson
authored andcommitted
performance tweak in reverse(::String) (#26300)
No reason not to pass a `sizehint` in this function since we know the exact number of bytes required.
1 parent ce26ed0 commit 05ff71f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/strings/substring.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ julia> join(reverse(collect(graphemes("ax̂e")))) # reverses graphemes
130130
```
131131
"""
132132
function reverse(s::Union{String,SubString{String}})::String
133-
sprint() do io
133+
sprint(sizehint=sizeof(s)) do io
134134
i, j = firstindex(s), lastindex(s)
135135
while i j
136136
c, j = s[j], prevind(s, j)

0 commit comments

Comments
 (0)