Skip to content

Commit 4eb9f83

Browse files
committed
Revert "Revert "faster string() for ASCIIString. helps #2050""
This reverts commit 57ad0dd.
1 parent f5a7c88 commit 4eb9f83

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

base/ascii.jl

+15-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ getindex(s::ASCIIString, r::Range1{Int}) = ASCIIString(getindex(s.data,r))
1919
getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
2020
search(s::ASCIIString, c::Char, i::Integer) = c < 0x80 ? search(s.data,uint8(c),i) : 0
2121
rsearch(s::ASCIIString, c::Char, i::Integer) = c < 0x80 ? rsearch(s.data,uint8(c),i) : 0
22-
string(a::ASCIIString, b::ASCIIString, c::ASCIIString...) =
23-
ASCIIString([a.data,b.data,map(s->s.data,c)...])
22+
23+
function string(c::ASCIIString...)
24+
n = 0
25+
for s in c
26+
n += length(s.data)
27+
end
28+
v = Array(Uint8,n)
29+
o = 1
30+
for s in c
31+
ls = length(s.data)
32+
unsafe_copy!(v, o, s.data, 1, ls)
33+
o += ls
34+
end
35+
ASCIIString(v)
36+
end
2437

2538
function ucfirst(s::ASCIIString)
2639
if 'a' <= s[1] <= 'z'

base/io.jl

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ end
2727
# all subtypes should implement this
2828
write(s::IO, x::Uint8) = error(typeof(s)," does not support byte I/O")
2929

30+
write(io::IO, xs...) = for x in xs write(io, x) end
31+
3032
if ENDIAN_BOM == 0x01020304
3133
function write(s::IO, x::Integer)
3234
sz = sizeof(x)

0 commit comments

Comments
 (0)